class EDTF::Set
Attributes
choice[RW]
dates[R]
earlier[RW]
later[RW]
Public Class Methods
new(*dates)
click to toggle source
# File lib/edtf/set.rb 15 def initialize(*dates) 16 @dates = ::Set.new(dates.flatten) 17 @choice, @later, @earlier = false, false, false 18 end
Public Instance Methods
<<(date)
click to toggle source
# File lib/edtf/set.rb 32 def <<(date) 33 dates << date 34 self 35 end
<=>(other)
click to toggle source
# File lib/edtf/set.rb 62 def <=>(other) 63 return nil unless other.respond_to?(:to_a) 64 to_a <=> other.to_a 65 end
each(&block)
click to toggle source
# File lib/edtf/set.rb 37 def each(&block) 38 if block_given? 39 to_a.each(&block) 40 self 41 else 42 to_enum 43 end 44 end
edtf()
click to toggle source
# File lib/edtf/set.rb 46 def edtf 47 parenthesize(dates.map { |d| 48 d.respond_to?(:edtf) ? d.edtf : d.to_s 49 }.sort.join(',')) 50 end
Also aliased as: to_s
initialize_copy(other)
click to toggle source
# File lib/edtf/set.rb 20 def initialize_copy(other) 21 @set = other.to_set 22 end
to_a()
click to toggle source
# File lib/edtf/set.rb 52 def to_a 53 dates.map { |d| Array(d) }.flatten.sort 54 end
to_set()
click to toggle source
# File lib/edtf/set.rb 56 def to_set 57 to_a.to_set 58 end
Private Instance Methods
parenthesize(string)
click to toggle source
# File lib/edtf/set.rb 73 def parenthesize(string) 74 p = choice? ? %w([ ]) : %w({ }) 75 p[-1,0] = '..' if earlier? 76 p[-1,0] = string unless string.empty? 77 p[-1,0] = '..' if later? 78 p.join 79 end