Class: Factbase::ToJSON
- Inherits:
-
Object
- Object
- Factbase::ToJSON
- Defined in:
- lib/factbase/to_json.rb
Overview
Instance Method Summary collapse
-
#initialize(fb, sorter = '_id') ⇒ ToJSON
constructor
Constructor.
-
#json ⇒ String
Convert the entire factbase into JSON.
Constructor Details
#initialize(fb, sorter = '_id') ⇒ ToJSON
Constructor.
39 40 41 42 |
# File 'lib/factbase/to_json.rb', line 39 def initialize(fb, sorter = '_id') @fb = fb @sorter = sorter end |
Instance Method Details
#json ⇒ String
Convert the entire factbase into JSON.
46 47 48 49 |
# File 'lib/factbase/to_json.rb', line 46 def json maps = Marshal.load(@fb.export) maps.sort_by { |m| m[@sorter] }.map { |m| m.sort.to_h }.to_json end |