Class: Alexa::Slot

Inherits:
Object
  • Object
show all
Defined in:
lib/alexa/slot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Slot

Returns a new instance of Slot.



5
6
7
8
9
# File 'lib/alexa/slot.rb', line 5

def initialize(attributes={})
  @name = attributes['name']
  @value = attributes['value']
  @resolutions = attributes['resolutions']
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/alexa/slot.rb', line 3

def name
  @name
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/alexa/slot.rb', line 3

def value
  @value
end

Instance Method Details

#as_json(options = {}) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/alexa/slot.rb', line 42

def as_json(options={})
  h = { name: name }
  # add other attributes only if they are present
  h.merge!(value: value) if value.present?
  h.merge!(resolutions: @resolutions) if @resolutions.present?
  h
end

#bad_match?Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/alexa/slot.rb', line 28

def bad_match?
  return false if !has_resolutions?
  resolution["status"]["code"] == "ER_SUCCESS_NO_MATCH"
end

#has_resolutions?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/alexa/slot.rb', line 33

def has_resolutions?
  @resolutions.present?
end

#matched?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/alexa/slot.rb', line 23

def matched?
  return false if !has_resolutions?
  resolution["status"]["code"] == "ER_SUCCESS_MATCH"
end

#matched_idObject



17
18
19
20
21
# File 'lib/alexa/slot.rb', line 17

def matched_id
  if matched?
    resolution["values"].first["value"]["id"]
  end
end

#matched_valueObject



11
12
13
14
15
# File 'lib/alexa/slot.rb', line 11

def matched_value
  if matched?
    resolution["values"].first["value"]["name"]
  end
end

#resolutionObject



37
38
39
40
# File 'lib/alexa/slot.rb', line 37

def resolution
  return nil if !has_resolutions?
  @resolutions["resolutionsPerAuthority"].first
end