Class: WitBot::Context

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#entitiesObject



14
15
16
# File 'lib/wit_bot/models/context.rb', line 14

def entities
  @entities ||= ContextEntities.new
end

#hash=(value) ⇒ Object (writeonly)

Sets the attribute hash

Parameters:

  • value

    the value to set the attribute hash to.



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

def hash=(value)
  @hash = value
end

#locationObject

Returns the value of attribute location.



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

def location
  @location
end

#reference_timeObject

Returns the value of attribute reference_time.



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

def reference_time
  @reference_time
end

#stateObject



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

def state
  @state ||= []
end

Class Method Details

.from_hash(json) ⇒ Object



35
36
37
# File 'lib/wit_bot/models/context.rb', line 35

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

Instance Method Details

#==(other) ⇒ Object



39
40
41
42
43
44
# File 'lib/wit_bot/models/context.rb', line 39

def ==(other)
  self.state == other.state &&
      self.reference_time == other.reference_time &&
      self.entities == other.entities &&
      self.location == other.location
end

#empty?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/wit_bot/models/context.rb', line 10

def empty?
  to_hash.empty?
end

#from_hash(h) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/wit_bot/models/context.rb', line 27

def from_hash(h)
  @state = Array.wrap h[:state]
  @reference_time = Date.parse h[:reference_time] if h[:reference_time]
  @entities = ContextEntities.from_hash h[:entities] if h[:entities]
  @location = h[:location]
  self
end

#to_hashObject



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

def to_hash
  h = {}
  h[:state] = state if state && !state.empty?
  h[:reference_time] = reference_time.iso8601 if reference_time
  h[:entities] = entities if @entities
  h[:location] = location if location
  h
end