Class: Natter::Entity
- Inherits:
-
Object
- Object
- Natter::Entity
- Defined in:
- lib/natter/entity.rb
Overview
Public: An entity is an attribute of an intent.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, type = EntityType::GENERIC, value = nil) ⇒ Entity
constructor
Public: Constructor.
-
#value ⇒ Object
Public: Returns the value of this entity.
-
#value=(v) ⇒ Object
Public: Set this entity’s value.
Constructor Details
#initialize(name, type = EntityType::GENERIC, value = nil) ⇒ Entity
Public: Constructor.
name - Must be unique within an individual intent. type - One of the pre-defined EntityType constants (default: ‘generic’) value - Will never be nil when generated by the parser but may be nil
for some rule definitions (default: nil).
12 13 14 15 16 |
# File 'lib/natter/entity.rb', line 12 def initialize(name, type = EntityType::GENERIC, value = nil) @name = name @type = type @value = value end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/natter/entity.rb', line 4 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/natter/entity.rb', line 4 def type @type end |
Instance Method Details
#value ⇒ Object
Public: Returns the value of this entity. If @type is ‘generic` then we just return @value, otherwise we will need to verify/compute the value to return.
Returns object or nil (if invalid @value)
30 31 32 33 34 35 36 37 |
# File 'lib/natter/entity.rb', line 30 def value case @type when EntityType::TIME return Chronic.parse(@value) # returns Time or nil else return @value end end |
#value=(v) ⇒ Object
Public: Set this entity’s value.
value - The new value.
21 22 23 |
# File 'lib/natter/entity.rb', line 21 def value=(v) @value = v end |