Class: Materialize::Entity
- Inherits:
-
Object
- Object
- Materialize::Entity
- Includes:
- Utils
- Defined in:
- lib/materialize/entity.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(attributes) ⇒ Entity
constructor
A new instance of Entity.
Methods included from Utils
Constructor Details
#initialize(attributes) ⇒ Entity
Returns a new instance of Entity.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/materialize/entity.rb', line 19 def initialize(attributes) @source = attributes raise "Attributes must be a hash" unless attributes.is_a?(Hash) attributes.each_pair do |key, value| value = attempt_entity_conversion(key, value) if collection?(value) instance_variable_set("@#{key}", value) (class << self; self; end).class_eval do attr_reader key.to_sym end end end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/materialize/entity.rb', line 7 def source @source end |
Class Method Details
.wrap(entities_data) ⇒ Object
11 12 13 |
# File 'lib/materialize/entity.rb', line 11 def wrap(entities_data) entities_data.map { |entity_data| new(entity_data) } end |
Instance Method Details
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/materialize/entity.rb', line 33 def empty? source.empty? end |