Class: WitBot::ContextEntities
- Inherits:
-
Object
- Object
- WitBot::ContextEntities
- Defined in:
- lib/wit_bot/models/context_entities.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#values ⇒ Object
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](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
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/wit_bot/models/context_entities.rb', line 3 def id @id end |
#values ⇒ Object
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_hash ⇒ Object
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 |