class BahaiDate::OccasionFactory
Constants
- DATES
- DATES_AFTER_172
- DATES_BEFORE_172
- OCCASIONS
Public Class Methods
find(occasion, year)
click to toggle source
# File lib/bahai_date/occasion_factory.rb, line 150 def self.find(occasion, year) if year < 172 all_dates = DATES.merge(DATES_BEFORE_172) else all_dates = DATES.merge(DATES_AFTER_172).merge(dates_lunar(year)) end all_dates.find { |_key, array| array.include? occasion }.first end
new(year, month, day)
click to toggle source
# File lib/bahai_date/occasion_factory.rb, line 140 def initialize(year, month, day) @year = year @month = month @day = day end
Private Class Methods
dates_lunar(year)
click to toggle source
# File lib/bahai_date/occasion_factory.rb, line 185 def self.dates_lunar(year) twin = Logic.twin_holy_days_date year birth_bab = BahaiDate.new(date: twin) birth_bab_string = "#{birth_bab.month.number}.#{birth_bab.day.number}" birth_bahaullah = BahaiDate.new(date: twin + 1) birth_bahaullah_string = "#{birth_bahaullah.month.number}.#{birth_bahaullah.day.number}" { birth_bab_string => [:birth_bab], birth_bahaullah_string => [:birth_bahaullah] } end
Public Instance Methods
occasions()
click to toggle source
# File lib/bahai_date/occasion_factory.rb, line 146 def occasions create_occasions_classes_from occasions_hashes end
Private Instance Methods
create_occasions_classes_from(hashes_array)
click to toggle source
# File lib/bahai_date/occasion_factory.rb, line 161 def create_occasions_classes_from(hashes_array) hashes_array.map! { |opts_hash| Occasion.new(opts_hash) } end
each_ids() { |DATES| ... }
click to toggle source
# File lib/bahai_date/occasion_factory.rb, line 174 def each_ids key = "#{@month}.#{@day}" yield DATES[key] if @year < 172 yield DATES_BEFORE_172[key] else yield DATES_AFTER_172[key] yield (self.class.dates_lunar(@year))[key] end end
occasions_hashes()
click to toggle source
# File lib/bahai_date/occasion_factory.rb, line 165 def occasions_hashes hashes_array = [] each_ids do | ids | next unless ids hashes_array += OCCASIONS.values_at(*ids) end hashes_array end