Class: Materialize::Entity

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/materialize/entity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#class_exists?

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

#sourceObject (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

Returns:

  • (Boolean)


33
34
35
# File 'lib/materialize/entity.rb', line 33

def empty?
  source.empty?
end