Class: WitBot::ContextEntities
- Inherits:
-
Object
- Object
- WitBot::ContextEntities
- Defined in:
- lib/wit_bot/models/context_entities.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](entity) ⇒ Object
- #[]=(entity, value, expressions = [value]) ⇒ Object
- #from_hash(json) ⇒ Object
-
#initialize ⇒ ContextEntities
constructor
A new instance of ContextEntities.
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ ContextEntities
3 4 5 |
# File 'lib/wit_bot/models/context_entities.rb', line 3 def initialize @hash = {} end |
Class Method Details
.from_hash(json) ⇒ Object
23 24 25 |
# File 'lib/wit_bot/models/context_entities.rb', line 23 def self.from_hash(json) self.new.from_hash json end |
Instance Method Details
#[](entity) ⇒ Object
6 7 8 |
# File 'lib/wit_bot/models/context_entities.rb', line 6 def [](entity) @hash[entity] end |
#[]=(entity, value, expressions = [value]) ⇒ Object
9 10 11 |
# File 'lib/wit_bot/models/context_entities.rb', line 9 def []=(entity, value, expressions=[value]) @hash[entity] = value.is_a?(EntityValue) ? value : EntityValue.new(value, expressions) end |
#from_hash(json) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/wit_bot/models/context_entities.rb', line 17 def from_hash(json) json.each do |object| self[object[:id]] = EntityValue.new object[:values] end self end |
#to_hash ⇒ Object
12 13 14 15 16 |
# File 'lib/wit_bot/models/context_entities.rb', line 12 def to_hash @hash.map do |id, values| {id: id, values: values} end end |