Class: Tricle::RangeData

Inherits:
Object
  • Object
show all
Defined in:
lib/tricle/range_data.rb

Instance Method Summary collapse

Constructor Details

#initializeRangeData

Returns a new instance of RangeData.



4
5
6
# File 'lib/tricle/range_data.rb', line 4

def initialize
  @data = {}
end

Instance Method Details

#add(key, val) ⇒ Object



8
9
10
11
# File 'lib/tricle/range_data.rb', line 8

def add(key, val)
  @data[key] ||= []
  @data[key] << val
end

#all_itemsObject



13
14
15
# File 'lib/tricle/range_data.rb', line 13

def all_items
  @data.values.flatten
end

#items_for_range(low, high) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/tricle/range_data.rb', line 17

def items_for_range(low, high)
  @data.reduce([]) { |memo, (key, values)|
    if key >= low && key < high
      memo + values
    else
      memo
    end
  }
end