Class: Alexa::Slot
- Inherits:
-
Object
- Object
- Alexa::Slot
- Defined in:
- lib/alexa/slot.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #bad_match? ⇒ Boolean
- #has_resolutions? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Slot
constructor
A new instance of Slot.
- #matched? ⇒ Boolean
- #matched_id ⇒ Object
- #matched_value ⇒ Object
- #resolution ⇒ Object
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
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/alexa/slot.rb', line 3 def name @name end |
#value ⇒ Object
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(={}) 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
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
33 34 35 |
# File 'lib/alexa/slot.rb', line 33 def has_resolutions? @resolutions.present? end |
#matched? ⇒ 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_id ⇒ Object
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_value ⇒ Object
11 12 13 14 15 |
# File 'lib/alexa/slot.rb', line 11 def matched_value if matched? resolution["values"].first["value"]["name"] end end |
#resolution ⇒ Object
37 38 39 40 |
# File 'lib/alexa/slot.rb', line 37 def resolution return nil if !has_resolutions? @resolutions["resolutionsPerAuthority"].first end |