Class: Exfuz::Group
- Inherits:
-
Object
- Object
- Exfuz::Group
- Defined in:
- lib/exfuz/group.rb
Instance Method Summary collapse
- #create(positions, keys) ⇒ Object
-
#initialize(positions, keys) ⇒ Group
constructor
A new instance of Group.
- #key_positions(key) ⇒ Object
- #positions(key) ⇒ Object
Constructor Details
#initialize(positions, keys) ⇒ Group
Returns a new instance of Group.
5 6 7 8 9 |
# File 'lib/exfuz/group.rb', line 5 def initialize(positions, keys) @data = {} @raw_positions = positions create(positions, keys) end |
Instance Method Details
#create(positions, keys) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/exfuz/group.rb', line 11 def create(positions, keys) indices = (0...positions.size).to_a keys.each do |key| @data[key] = indices.group_by { |idx| positions[idx].slice(key) } .values end end |
#key_positions(key) ⇒ Object
19 20 21 22 23 |
# File 'lib/exfuz/group.rb', line 19 def key_positions(key) @data[key].map do |grouping_indices| @raw_positions[grouping_indices.first].slice(key) end end |
#positions(key) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/exfuz/group.rb', line 25 def positions(key) @data[key].each_with_object({}) do |grouping_indices, result| key_position = @raw_positions[grouping_indices.first].slice(key) result[key_position] = grouping_indices.map do |grouping_idx| @raw_positions[grouping_idx] end end end |