Class: Factbase::Flatten
- Inherits:
-
Object
- Object
- Factbase::Flatten
- Defined in:
- lib/factbase/flatten.rb
Overview
Make maps suitable for printing.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(maps, sorter = '_id') ⇒ Flatten
constructor
Constructor.
-
#it ⇒ Array<HashMap>
Improve the maps.
Constructor Details
#initialize(maps, sorter = '_id') ⇒ Flatten
Constructor.
32 33 34 35 |
# File 'lib/factbase/flatten.rb', line 32 def initialize(maps, sorter = '_id') @maps = maps @sorter = sorter end |
Instance Method Details
#it ⇒ Array<HashMap>
Improve the maps.
39 40 41 42 43 44 |
# File 'lib/factbase/flatten.rb', line 39 def it @maps .sort_by { |m| m[@sorter] || [] } .map { |m| m.sort.to_h } .map { |m| m.transform_values { |v| v.size == 1 ? v[0] : v } } end |