Class: WitBot::ContextEntities

Inherits:
Object
  • Object
show all
Defined in:
lib/wit_bot/models/context_entities.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContextEntities

Returns a new instance of ContextEntities.



6
7
8
# File 'lib/wit_bot/models/context_entities.rb', line 6

def initialize
  @hash = {}
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/wit_bot/models/context_entities.rb', line 3

def id
  @id
end

#valuesObject

Returns the value of attribute values.



4
5
6
# File 'lib/wit_bot/models/context_entities.rb', line 4

def values
  @values
end

Class Method Details

.from_hash(json) ⇒ Object



26
27
28
# File 'lib/wit_bot/models/context_entities.rb', line 26

def self.from_hash(json)
  self.new.from_hash json
end

Instance Method Details

#==(other) ⇒ Object



30
31
32
# File 'lib/wit_bot/models/context_entities.rb', line 30

def ==(other)
  self.id == other.id && self.values == other.values
end

#[](entity) ⇒ Object



9
10
11
# File 'lib/wit_bot/models/context_entities.rb', line 9

def [](entity)
  @hash[entity]
end

#[]=(entity, value, expressions = [value]) ⇒ Object



12
13
14
# File 'lib/wit_bot/models/context_entities.rb', line 12

def []=(entity, value, expressions=[value])
  @hash[entity] = value.is_a?(EntityValue) ? value : EntityValue.new(value, expressions)
end

#from_hash(json) ⇒ Object



20
21
22
23
24
25
# File 'lib/wit_bot/models/context_entities.rb', line 20

def from_hash(json)
  json.each do |object|
    self[object[:id]] = EntityValue.new object[:values]
  end
  self
end

#to_hashObject



15
16
17
18
19
# File 'lib/wit_bot/models/context_entities.rb', line 15

def to_hash
  @hash.map do |id, values|
    {id: id, values: values}
  end
end