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(&block) ⇒ 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
62 63 64 65 |
# File 'lib/edtf/set.rb', line 62 def <=>(other) return nil unless other.respond_to?(:to_a) to_a <=> other.to_a end |
#each(&block) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/edtf/set.rb', line 37 def each(&block) if block_given? to_a.each(&block) self else to_enum end end |
#edtf ⇒ Object Also known as: to_s
46 47 48 49 50 |
# File 'lib/edtf/set.rb', line 46 def edtf parenthesize(dates.map { |d| d.respond_to?(:edtf) ? d.edtf : d.to_s }.sort.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
52 53 54 |
# File 'lib/edtf/set.rb', line 52 def to_a dates.map { |d| Array(d) }.flatten.sort end |
#to_set ⇒ Object
56 57 58 |
# File 'lib/edtf/set.rb', line 56 def to_set to_a.to_set end |