Class: BahaiDate::BahaiDate
- Inherits:
-
Object
- Object
- BahaiDate::BahaiDate
- Defined in:
- lib/bahai_date/bahai_date.rb
Constant Summary collapse
- AYYAM_I_HA =
-1
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#gregorian_date ⇒ Object
readonly
Returns the value of attribute gregorian_date.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#weekday ⇒ Object
readonly
Returns the value of attribute weekday.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #+(val) ⇒ Object
- #-(val) ⇒ Object
-
#initialize(params) ⇒ BahaiDate
constructor
A new instance of BahaiDate.
- #long_format ⇒ Object
- #occasions ⇒ Object
- #short_format ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(params) ⇒ BahaiDate
Returns a new instance of BahaiDate.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bahai_date/bahai_date.rb', line 7 def initialize(params) if params[:date] @gregorian_date = params[:date] year, month, day = from_gregorian @year = Year.new(year) @month = Month.new(month) @day = Day.new(day) elsif params[:year] && params[:month] && params[:day] @year = Year.new(params[:year]) @month = Month.new(params[:month]) @day = Day.new(params[:day]) validate_ayyam_i_ha @gregorian_date = to_gregorian else fail ArgumentError, 'Invalid arguments. Use a hash with :date or with :year, :month, and :day.' end @weekday = Weekday.new(weekday_from_gregorian) end |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
5 6 7 |
# File 'lib/bahai_date/bahai_date.rb', line 5 def day @day end |
#gregorian_date ⇒ Object (readonly)
Returns the value of attribute gregorian_date.
5 6 7 |
# File 'lib/bahai_date/bahai_date.rb', line 5 def gregorian_date @gregorian_date end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
5 6 7 |
# File 'lib/bahai_date/bahai_date.rb', line 5 def month @month end |
#weekday ⇒ Object (readonly)
Returns the value of attribute weekday.
5 6 7 |
# File 'lib/bahai_date/bahai_date.rb', line 5 def weekday @weekday end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
5 6 7 |
# File 'lib/bahai_date/bahai_date.rb', line 5 def year @year end |
Instance Method Details
#+(val) ⇒ Object
42 43 44 |
# File 'lib/bahai_date/bahai_date.rb', line 42 def +(val) self.class.new(date: @gregorian_date + val) end |
#-(val) ⇒ Object
46 47 48 |
# File 'lib/bahai_date/bahai_date.rb', line 46 def -(val) self.class.new(date: @gregorian_date - val) end |
#long_format ⇒ Object
34 35 36 |
# File 'lib/bahai_date/bahai_date.rb', line 34 def long_format "#{@weekday} #{@day.number} #{@month} #{@year.bahai_era} B.E." end |
#occasions ⇒ Object
26 27 28 |
# File 'lib/bahai_date/bahai_date.rb', line 26 def occasions OccasionFactory.new(@year.bahai_era, @month.number, @day.number).occasions end |
#short_format ⇒ Object
38 39 40 |
# File 'lib/bahai_date/bahai_date.rb', line 38 def short_format "#{@day.number} #{@month} #{@year.bahai_era}" end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/bahai_date/bahai_date.rb', line 30 def to_s "#{@year.bahai_era}.#{@month.number}.#{@day.number}" end |