Class: Taza::Entity

Inherits:
Object show all
Defined in:
lib/taza/entity.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash, fixture) ⇒ Entity

Creates a entity, pass in a hash to be methodized and the fixture to look up other fixtures (not entirely happy with this abstraction)



4
5
6
7
8
# File 'lib/taza/entity.rb', line 4

def initialize(hash,fixture)
  @hash = hash
  @fixture = fixture
  define_methods_for_hash_keys
end

Instance Method Details

#define_methods_for_hash_keysObject

This method converts hash keys into methods onto the entity



11
12
13
14
15
16
17
# File 'lib/taza/entity.rb', line 11

def define_methods_for_hash_keys
  @hash.keys.each do |key|
    create_method(key) do
      get_value_for_entry(key)
    end
  end
end

#get_value_for_entry(key) ⇒ Object

This method will lookup another fixture if a pluralized fixture exists otherwise return the value in the hash



20
21
22
23
24
25
26
# File 'lib/taza/entity.rb', line 20

def get_value_for_entry(key) # :nodoc:
  if @fixture.pluralized_fixture_exists?(key)
    @fixture.get_fixture_entity(key.pluralize_to_sym,@hash[key])
  else
    @hash[key]
  end
end