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.
36 37 38 39 40 |
# File 'lib/iso8601/date.rb', line 36 def initialize(input) @original = input @atoms = atomize(input) @date = compose(@atoms) end |
Instance Attribute Details
#atoms ⇒ Object (readonly)
The original atoms
28 29 30 |
# File 'lib/iso8601/date.rb', line 28 def atoms @atoms end |
#separator ⇒ Object (readonly)
The separator used in the original ISO 8601 string.
32 33 34 |
# File 'lib/iso8601/date.rb', line 32 def separator @separator end |
Instance Method Details
#+(other) ⇒ ISO8601::Date
Forwards the date the given amount of days.
56 57 58 59 |
# File 'lib/iso8601/date.rb', line 56 def +(other) other = other.to_days if other.respond_to?(:to_days) ISO8601::Date.new((@date + other).iso8601) end |
#-(other) ⇒ ISO8601::Date
Backwards the date the given amount of days.
67 68 69 70 |
# File 'lib/iso8601/date.rb', line 67 def -(other) other = other.to_days if other.respond_to?(:to_days) ISO8601::Date.new((@date - other).iso8601) end |
#==(other) ⇒ Boolean
82 83 84 |
# File 'lib/iso8601/date.rb', line 82 def ==(other) (hash == other.hash) end |
#eql?(other) ⇒ Boolean
90 91 92 |
# File 'lib/iso8601/date.rb', line 90 def eql?(other) (hash == other.hash) end |
#hash ⇒ Fixnum
96 97 98 |
# File 'lib/iso8601/date.rb', line 96 def hash [atoms, self.class].hash end |
#to_a ⇒ Object
Converts self to an array of atoms.
74 75 76 |
# File 'lib/iso8601/date.rb', line 74 def to_a [year, month, day] end |
#week ⇒ Integer
The calendar week number (1-53)
46 47 48 |
# File 'lib/iso8601/date.rb', line 46 def week @date.cweek end |