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
-
#+(other) ⇒ ISO8601::Date
Forwards the date the given amount of days.
-
#-(other) ⇒ ISO8601::Date
Backwards the date the given amount of days.
- #==(other) ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Fixnum
-
#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.
31 32 33 34 35 |
# File 'lib/iso8601/date.rb', line 31 def initialize(input) @original = input @atoms = atomize(input) @date = compose(@atoms) end |
Instance Attribute Details
#atoms ⇒ Object (readonly)
The original atoms
25 26 27 |
# File 'lib/iso8601/date.rb', line 25 def atoms @atoms end |
#separator ⇒ Object (readonly)
The separator used in the original ISO 8601 string.
28 29 30 |
# File 'lib/iso8601/date.rb', line 28 def separator @separator end |
Instance Method Details
#+(other) ⇒ ISO8601::Date
Forwards the date the given amount of days.
49 50 51 |
# File 'lib/iso8601/date.rb', line 49 def +(other) ISO8601::Date.new((@date + other).iso8601) end |
#-(other) ⇒ ISO8601::Date
Backwards the date the given amount of days.
58 59 60 |
# File 'lib/iso8601/date.rb', line 58 def -(other) ISO8601::Date.new((@date - other).iso8601) end |
#==(other) ⇒ Boolean
70 71 72 |
# File 'lib/iso8601/date.rb', line 70 def ==(other) (hash == other.hash) end |
#eql?(other) ⇒ Boolean
77 78 79 |
# File 'lib/iso8601/date.rb', line 77 def eql?(other) (hash == other.hash) end |
#hash ⇒ Fixnum
82 83 84 |
# File 'lib/iso8601/date.rb', line 82 def hash [atoms, self.class].hash end |
#to_a ⇒ Object
Converts self to an array of atoms.
63 64 65 |
# File 'lib/iso8601/date.rb', line 63 def to_a [year, month, day] end |
#week ⇒ Integer
The calendar week number (1-53)
40 41 42 |
# File 'lib/iso8601/date.rb', line 40 def week @date.cweek end |