Class: EDTF::Set
- Inherits:
-
Object
- Object
- EDTF::Set
- Extended by:
- Forwardable
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/edtf/set.rb
Instance Attribute Summary collapse
-
#choice ⇒ Object
Returns the value of attribute choice.
-
#earlier ⇒ Object
Returns the value of attribute earlier.
-
#later ⇒ Object
Returns the value of attribute later.
Instance Method Summary collapse
- #<<(date) ⇒ Object
- #<=>(other) ⇒ Object
- #each ⇒ Object
- #edtf ⇒ Object (also: #to_s)
-
#initialize(*dates) ⇒ Set
constructor
A new instance of Set.
- #initialize_copy(other) ⇒ Object
- #to_a ⇒ Object
- #to_set ⇒ Object
Constructor Details
#initialize(*dates) ⇒ Set
Returns a new instance of Set.
15 16 17 18 |
# File 'lib/edtf/set.rb', line 15 def initialize(*dates) @dates = ::Set.new(dates.flatten) @choice, @later, @earlier = false, false, false end |
Instance Attribute Details
#choice ⇒ Object
Returns the value of attribute choice.
12 13 14 |
# File 'lib/edtf/set.rb', line 12 def choice @choice end |
#earlier ⇒ Object
Returns the value of attribute earlier.
12 13 14 |
# File 'lib/edtf/set.rb', line 12 def earlier @earlier end |
#later ⇒ Object
Returns the value of attribute later.
12 13 14 |
# File 'lib/edtf/set.rb', line 12 def later @later end |
Instance Method Details
#<<(date) ⇒ Object
32 33 34 35 |
# File 'lib/edtf/set.rb', line 32 def <<(date) dates << date self end |
#<=>(other) ⇒ Object
60 61 62 63 |
# File 'lib/edtf/set.rb', line 60 def <=>(other) return nil unless other.respond_to?(:to_a) to_a <=> other.to_a end |
#each ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/edtf/set.rb', line 37 def each if block_given? to_a.each(&Proc.new) self else to_enum end end |
#edtf ⇒ Object Also known as: to_s
46 47 48 |
# File 'lib/edtf/set.rb', line 46 def edtf parenthesize(dates.map { |d| d.respond_to?(:edtf) ? d.edtf : d.to_s }.join(', ')) end |
#initialize_copy(other) ⇒ Object
20 21 22 |
# File 'lib/edtf/set.rb', line 20 def initialize_copy(other) @set = other.to_set end |
#to_a ⇒ Object
50 51 52 |
# File 'lib/edtf/set.rb', line 50 def to_a dates.map { |d| Array(d) }.flatten end |
#to_set ⇒ Object
54 55 56 |
# File 'lib/edtf/set.rb', line 54 def to_set to_a.to_set end |