Class: SimpleRepresenter::Representer
- Inherits:
-
Object
- Object
- SimpleRepresenter::Representer
- Includes:
- Definable
- Defined in:
- lib/simple_representer/representer.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#represented ⇒ Object
readonly
Returns the value of attribute represented.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(represented, **options) ⇒ Representer
constructor
A new instance of Representer.
-
#to_h ⇒ Object
(also: #to_hash)
return hash with symbols as keys.
- #to_json(*_args) ⇒ Object
Methods included from Definable
Constructor Details
#initialize(represented, **options) ⇒ Representer
Returns a new instance of Representer.
15 16 17 18 |
# File 'lib/simple_representer/representer.rb', line 15 def initialize(represented, **) @represented = represented.is_a?(Hash) ? represented.clone.extend(CallableHash) : represented @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/simple_representer/representer.rb', line 13 def @options end |
#represented ⇒ Object (readonly)
Returns the value of attribute represented.
13 14 15 |
# File 'lib/simple_representer/representer.rb', line 13 def represented @represented end |
Class Method Details
.for_collection(collection, **options) ⇒ Object
32 33 34 |
# File 'lib/simple_representer/representer.rb', line 32 def self.for_collection(collection, **) Collection.new(self, collection, ) end |
Instance Method Details
#to_h ⇒ Object Also known as: to_hash
return hash with symbols as keys
21 22 23 24 25 |
# File 'lib/simple_representer/representer.rb', line 21 def to_h build_result do |obj, result| obj[result[0]] = result[1] end end |
#to_json(*_args) ⇒ Object
28 29 30 |
# File 'lib/simple_representer/representer.rb', line 28 def to_json(*_args) ::Oj.generate(to_h) end |