Class: Builder::JsonFormat

Inherits:
HashStructure show all
Defined in:
lib/builder/json_format.rb

Instance Method Summary collapse

Methods inherited from HashStructure

#<<, #array_mode, #content!, #method_missing, #root!, #tag!, #text!

Methods inherited from Abstract

#comment!, #declare!, #instruct!, #nil?

Constructor Details

#initialize(options = {}) ⇒ JsonFormat

Returns a new instance of JsonFormat.



6
7
8
9
10
11
12
13
# File 'lib/builder/json_format.rb', line 6

def initialize(options = {})
  # @default_content_key is used in such case: markup.key(value, :attr_key => attr_value)
  # in this case, we need some key for value.
  @default_content_key  = (options[:default_content_key] || :content).to_sym
  @include_root = options[:include_root]
  @target = {}
  @array_mode = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Builder::HashStructure

Instance Method Details

#target!Object



15
16
17
18
19
20
21
# File 'lib/builder/json_format.rb', line 15

def target!
  if @include_root
    @target.to_json
  else
    @target[@root].to_json
  end
end