Class: Tricle::RangeData
- Inherits:
-
Object
- Object
- Tricle::RangeData
- Defined in:
- lib/tricle/range_data.rb
Instance Method Summary collapse
- #add(key, val) ⇒ Object
- #all_items ⇒ Object
-
#initialize ⇒ RangeData
constructor
A new instance of RangeData.
- #items_for_range(low, high) ⇒ Object
Constructor Details
#initialize ⇒ RangeData
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_items ⇒ Object
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 |