Class: ISO8601::Date
- Inherits:
-
Object
- Object
- ISO8601::Date
- Extended by:
- Forwardable
- Defined in:
- lib/iso8601/date.rb
Overview
A Date representation
Instance Attribute Summary collapse
-
#atoms ⇒ Object
readonly
The original atoms.
-
#separator ⇒ Object
readonly
The separator used in the original ISO 8601 string.
Instance Method Summary collapse
-
#+(days) ⇒ ISO8601::Date
Forwards the date the given amount of days.
-
#-(days) ⇒ ISO8601::Date
Backwards the date the given amount of days.
-
#initialize(input) ⇒ Date
constructor
A new instance of Date.
-
#to_a ⇒ Object
Converts self to an array of atoms.
-
#week ⇒ Integer
The calendar week number (1-53).
Constructor Details
#initialize(input) ⇒ Date
Returns a new instance of Date.
29 30 31 32 33 |
# File 'lib/iso8601/date.rb', line 29 def initialize(input) @original = input @atoms = atomize(input) @date = compose(@atoms) end |
Instance Attribute Details
#atoms ⇒ Object (readonly)
The original atoms
23 24 25 |
# File 'lib/iso8601/date.rb', line 23 def atoms @atoms end |
#separator ⇒ Object (readonly)
The separator used in the original ISO 8601 string.
26 27 28 |
# File 'lib/iso8601/date.rb', line 26 def separator @separator end |
Instance Method Details
#+(days) ⇒ ISO8601::Date
Forwards the date the given amount of days.
47 48 49 |
# File 'lib/iso8601/date.rb', line 47 def +(days) ISO8601::Date.new((@date + days).iso8601) end |
#-(days) ⇒ ISO8601::Date
Backwards the date the given amount of days.
56 57 58 |
# File 'lib/iso8601/date.rb', line 56 def -(days) ISO8601::Date.new((@date - days).iso8601) end |
#to_a ⇒ Object
Converts self to an array of atoms.
61 62 63 |
# File 'lib/iso8601/date.rb', line 61 def to_a [year, month, day] end |
#week ⇒ Integer
The calendar week number (1-53)
38 39 40 |
# File 'lib/iso8601/date.rb', line 38 def week @date.cweek end |