Class: WitBot::WitModel::Entity

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

Constant Summary collapse

@@entities =
{}

Instance Attribute Summary

Attributes inherited from Base

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

all, #create, #delete, #from_response_data, get, #get, #on_delete, #to_h

Constructor Details

#initialize(id, doc = false, values = nil, request: false) ⇒ Entity

Returns a new instance of Entity.



12
13
14
15
16
17
18
19
# File 'lib/wit_bot/models/wit/entity.rb', line 12

def initialize(id, doc=false, values=nil, request: false)
  super
  @doc = doc
  @values = values
  @uuid = nil

  @@entities[name] = self
end

Class Method Details

.find(name, create = true) ⇒ Object



25
26
27
# File 'lib/wit_bot/models/wit/entity.rb', line 25

def self.find(name, create=true)
  @@entities[name] || create && Entity.new(id: name, request: true)
end

Instance Method Details

#==(other) ⇒ Object



29
30
31
# File 'lib/wit_bot/models/wit/entity.rb', line 29

def ==(other)
  self.name == other.name
end

#model(role, data) ⇒ Object



21
22
23
# File 'lib/wit_bot/models/wit/entity.rb', line 21

def model(role, data)
  EntityModel.new self, role, data
end