Class: JSONBuilder::Elements
- Inherits:
-
Object
- Object
- JSONBuilder::Elements
- Defined in:
- lib/json_builder/elements.rb
Instance Attribute Summary collapse
-
#compilers ⇒ Object
Returns the value of attribute compilers.
Instance Method Summary collapse
-
#initialize(scope, items, &block) ⇒ Elements
constructor
Public: Creates a new instance of the Elements that generates an array of JSONBuilder::Member objects.
-
#to_s ⇒ Object
Public: Generates the array JSON block local values.
Constructor Details
#initialize(scope, items, &block) ⇒ Elements
Public: Creates a new instance of the Elements that generates an array of JSONBuilder::Member objects.
scope - The view scope context for any variables. items - The array of elements to create values from. block - Yielding any block passed to the element.
Raises InvalidArgument if the items passed does not respond to each. Returns a new instance of Elements.
14 15 16 17 18 19 20 21 22 |
# File 'lib/json_builder/elements.rb', line 14 def initialize(scope, items, &block) raise InvalidArgument.new('items does not respond to each') unless items.respond_to?(:each) @compilers = [] items.each do |item| @compilers << Value.new(scope, item, &block) end end |
Instance Attribute Details
#compilers ⇒ Object
Returns the value of attribute compilers.
3 4 5 |
# File 'lib/json_builder/elements.rb', line 3 def compilers @compilers end |
Instance Method Details
#to_s ⇒ Object
Public: Generates the array JSON block local values
Returns a formated JSON String
27 28 29 |
# File 'lib/json_builder/elements.rb', line 27 def to_s "[#{@compilers.collect(&:to_s).join(', ')}]" end |