Class: WitBot::EntityModel

Inherits:
Object
  • 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(entity, role, raw) ⇒ EntityModel

Returns a new instance of EntityModel.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 36

def initialize(entity, role, raw)
  @entity = entity
  @role = role
  @raw = raw.with_indifferent_access

  @value = case @raw[:type] && @raw[:type].to_sym
           when :value
             @raw[:value].to_s
           else
             @raw[:value]
           end

  @others = []
end

Instance Attribute Details

#allObject

Returns the value of attribute all.



33
34
35
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 33

def all
  @all
end

#entityObject (readonly)

Returns the value of attribute entity.



34
35
36
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 34

def entity
  @entity
end

#rawObject (readonly)

Returns the value of attribute raw.



34
35
36
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 34

def raw
  @raw
end

#roleObject (readonly)

Returns the value of attribute role.



34
35
36
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 34

def role
  @role
end

#valueObject (readonly)

Returns the value of attribute value.



34
35
36
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 34

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



55
56
57
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 55

def ==(other)
  self.entity == other.entity && self.value == other.value
end

#othersObject



51
52
53
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 51

def others
  all - [self]
end

#to_sObject



59
60
61
# File 'lib/wit_bot/models/wit/entity/entity_model.rb', line 59

def to_s
  value.to_s
end