Class: Croudia::Object::Base
- Inherits:
-
Object
- Object
- Croudia::Object::Base
- Defined in:
- lib/croudia/object/base.rb
Direct Known Subclasses
Cursor, Entities, Identity, Location, Relationship, SearchMetadata, SearchResult, Source, Tokens, Trend, TrendDetails
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
Class Method Summary collapse
- .attr_reader_as_array_object(attribute, object) ⇒ Object
- .attr_reader_as_object(attribute, object) ⇒ Object
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(attrs = {}) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 |
# File 'lib/croudia/object/base.rb', line 6 def initialize(attrs = {}) @attrs = attrs || {} @attrs.each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
4 5 6 |
# File 'lib/croudia/object/base.rb', line 4 def attrs @attrs end |
Class Method Details
.attr_reader_as_array_object(attribute, object) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/croudia/object/base.rb', line 20 def attr_reader_as_array_object(attribute, object) define_method(attribute.to_s) do @attr[attribute.to_s].map do |obj| Object.const_get(object.to_s).new(obj) end end end |
.attr_reader_as_object(attribute, object) ⇒ Object
14 15 16 17 18 |
# File 'lib/croudia/object/base.rb', line 14 def attr_reader_as_object(attribute, object) define_method(attribute.to_s) do Object.const_get(object.to_s).new(@attrs[attribute.to_s]) end end |