Class: SimpleRepresenter::Collection
- Inherits:
-
Object
- Object
- SimpleRepresenter::Collection
- Defined in:
- lib/simple_representer/collection.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#representer ⇒ Object
readonly
Returns the value of attribute representer.
Instance Method Summary collapse
-
#initialize(representer, collection = [], options = {}) ⇒ Collection
constructor
A new instance of Collection.
- #to_h ⇒ Object (also: #to_hash)
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(representer, collection = [], options = {}) ⇒ Collection
Returns a new instance of Collection.
9 10 11 12 13 |
# File 'lib/simple_representer/collection.rb', line 9 def initialize(representer, collection = [], = {}) @representer = representer @collection = collection @options = end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
7 8 9 |
# File 'lib/simple_representer/collection.rb', line 7 def collection @collection end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/simple_representer/collection.rb', line 7 def @options end |
#representer ⇒ Object (readonly)
Returns the value of attribute representer.
7 8 9 |
# File 'lib/simple_representer/collection.rb', line 7 def representer @representer end |
Instance Method Details
#to_h ⇒ Object Also known as: to_hash
15 16 17 |
# File 'lib/simple_representer/collection.rb', line 15 def to_h collection.map { |elem| representer.new(elem, **).to_h } end |
#to_json(*_args) ⇒ Object
20 21 22 |
# File 'lib/simple_representer/collection.rb', line 20 def to_json(*_args) ::Oj.generate(to_h) end |