Class: Daterval::Set
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(*pairs) ⇒ Set
constructor
A new instance of Set.
- #merged! ⇒ Object
Constructor Details
#initialize(*pairs) ⇒ Set
Returns a new instance of Set.
5 6 7 |
# File 'lib/daterval/set.rb', line 5 def initialize(*pairs) @list = pairs end |
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
34 35 36 |
# File 'lib/daterval/set.rb', line 34 def list @list end |
Instance Method Details
#each ⇒ Object
9 10 11 |
# File 'lib/daterval/set.rb', line 9 def each list.each { |pair| yield pair } end |
#merged! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/daterval/set.rb', line 13 def merged! sorted = list.sort_by(&:begin) new_list = [] sorted.each do |pair| merged = false new_list.each_with_index do |pair_x, index_x| if pair.overlaps?(pair_x) new_list[index_x] = pair.overlap(pair_x) merged = true end end new_list << pair unless merged end @list = new_list self end |