Class: EDTF::Interval
- Inherits:
-
Object
- Object
- EDTF::Interval
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/edtf/interval.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #bounds ⇒ Object
- #edtf ⇒ Object (also: #to_s)
-
#initialize(from = :open, to = :open) ⇒ Interval
constructor
A new instance of Interval.
-
#to_range ⇒ Object
TODO how to handle +/- Infinity for Dates?.
- #unknown_start! ⇒ Object
- #unknown_start? ⇒ Boolean
Constructor Details
#initialize(from = :open, to = :open) ⇒ Interval
Returns a new instance of Interval.
13 14 15 |
# File 'lib/edtf/interval.rb', line 13 def initialize(from = :open, to = :open) @from, @to = from, to end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
11 12 13 |
# File 'lib/edtf/interval.rb', line 11 def from @from end |
#to ⇒ Object
Returns the value of attribute to.
11 12 13 |
# File 'lib/edtf/interval.rb', line 11 def to @to end |
Instance Method Details
#bounds ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/edtf/interval.rb', line 64 def bounds case when open_end?, to.day_precision? to when to.month_precision? to.end_of_month else to.end_of_year end end |
#edtf ⇒ Object Also known as: to_s
75 76 77 78 79 80 |
# File 'lib/edtf/interval.rb', line 75 def edtf [ @from.send(@from.respond_to?(:edtf) ? :edtf : :to_s), @to.send(@to.respond_to?(:edtf) ? :edtf : :to_s) ].join('/') end |
#to_range ⇒ Object
TODO how to handle +/- Infinity for Dates?
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/edtf/interval.rb', line 53 def to_range case when open? nil when unknown_end? nil else Range.new(unknown_start? ? Date.new : @from, bounds) end end |
#unknown_start! ⇒ Object
47 48 49 |
# File 'lib/edtf/interval.rb', line 47 def unknown_start! @from = :unknown end |
#unknown_start? ⇒ Boolean
43 44 45 |
# File 'lib/edtf/interval.rb', line 43 def unknown_start? @from == :unknown end |