class BahaiDate::Year

Constants

TITLES
TITLES_EN
TITLES_HTML

Attributes

bahai_era[R]
kull_i_shay[R]
months[R]
number[R]
vahid[R]

Public Class Methods

new(number_arg) click to toggle source
# File lib/bahai_date/year.rb, line 9
def initialize(number_arg)
  validate number_arg
  @bahai_era = number_arg.to_i
  calculate_number_vahid_and_kull_i_shay
  @months = {}
end

Public Instance Methods

add_month(month_number) click to toggle source
# File lib/bahai_date/year.rb, line 32
def add_month(month_number)
  if @months[month_number]
    @months[month_number]
  else
    @months[month_number] = Month.new(month_number)
  end
end
html() click to toggle source
# File lib/bahai_date/year.rb, line 28
def html
  TITLES_HTML[title_index]
end
title() click to toggle source
# File lib/bahai_date/year.rb, line 20
def title
  TITLES[title_index]
end
to_s() click to toggle source
# File lib/bahai_date/year.rb, line 16
def to_s
  @bahai_era.to_s
end
translation() click to toggle source
# File lib/bahai_date/year.rb, line 24
def translation
  TITLES_EN[title_index]
end

Private Instance Methods

calculate_number_vahid_and_kull_i_shay() click to toggle source
# File lib/bahai_date/year.rb, line 53
def calculate_number_vahid_and_kull_i_shay
  @vahid, @number = (@bahai_era - 1).divmod(19)
  @kull_i_shay, @vahid = @vahid.divmod(19)
  @number += 1
  @vahid += 1
  @kull_i_shay += 1
end
title_index() click to toggle source
# File lib/bahai_date/year.rb, line 42
def title_index
  @number - 1
end
validate(number_arg) click to toggle source
# File lib/bahai_date/year.rb, line 46
def validate(number_arg)
  number = number_arg.to_i
  return unless number < 1

  fail ArgumentError, "'#{number}' is not a valid year. Please use a number greater than or equal to 1."
end