Class: Levels::Output::JSON
- Inherits:
-
Object
- Object
- Levels::Output::JSON
- Defined in:
- lib/levels/output/json.rb
Constant Summary collapse
- SPACE =
" ".freeze
- JSON_OPTS =
{ indent: SPACE * 2, space: SPACE * 1, space_before: SPACE * 0, object_nl: "\n", array_nl: "\n", allow_nan: false, max_nesting: 10 }
Instance Method Summary collapse
- #generate(enumerator) ⇒ Object
-
#initialize(json_opts = nil) ⇒ JSON
constructor
A new instance of JSON.
Constructor Details
#initialize(json_opts = nil) ⇒ JSON
Returns a new instance of JSON.
16 17 18 |
# File 'lib/levels/output/json.rb', line 16 def initialize(json_opts = nil) @json_opts = json_opts || JSON_OPTS end |
Instance Method Details
#generate(enumerator) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/levels/output/json.rb', line 20 def generate(enumerator) hash = {} enumerator.each do |group_name, group| hash[group_name] = {} group.each do |key, value| hash[group_name][key] = value end end ::JSON.generate(hash, @json_opts) end |