class Natter::Entity

Public: An entity is an attribute of an intent.

Attributes

name[RW]
type[RW]

Public Class Methods

new(name, type = EntityType::GENERIC, value = nil) click to toggle source

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).
# File lib/natter/entity.rb, line 12
def initialize(name, type = EntityType::GENERIC, value = nil)
  @name = name
  @type = type
  @value = value
end

Public Instance Methods

value() click to toggle source

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)

# 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) click to toggle source

Public: Set this entity's value.

value - The new value.

# File lib/natter/entity.rb, line 21
def value=(v)
  @value = v
end