Class: EDTF::Set

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable, Enumerable
Defined in:
lib/edtf/set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#choiceObject

Returns the value of attribute choice.



12
13
14
# File 'lib/edtf/set.rb', line 12

def choice
  @choice
end

#earlierObject

Returns the value of attribute earlier.



12
13
14
# File 'lib/edtf/set.rb', line 12

def earlier
  @earlier
end

#laterObject

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

#edtfObject 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_aObject



52
53
54
# File 'lib/edtf/set.rb', line 52

def to_a
  dates.map { |d| Array(d) }.flatten.sort
end

#to_setObject



56
57
58
# File 'lib/edtf/set.rb', line 56

def to_set
  to_a.to_set
end