Class: WitBot::EntityModelProxy

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/wit_bot/models/wit/entity/entity_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_entities) ⇒ EntityModelProxy

Returns a new instance of EntityModelProxy.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 5

def initialize(raw_entities)
  @raw = raw_entities

  super Hash[raw_entities.map do |(role, all)|
    all = all.map do |data|
      entity_name = data[:entity] || role
      entity = WitModel::Entity.find(entity_name, create: false)
      entity.model role, data
    end

    data = all.length == 1 ? all.first : all

    create_getter role

    [role, data]
  end]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*_) ⇒ Object



23
24
25
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 23

def method_missing(*_)
  nil
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



3
4
5
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 3

def raw
  @raw
end