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



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

#eachObject



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

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



50
51
52
# File 'lib/edtf/set.rb', line 50

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

#to_setObject



54
55
56
# File 'lib/edtf/set.rb', line 54

def to_set
	to_a.to_set
end