Class: Attentive::CompositeEntity

Inherits:
Entity show all
Defined in:
lib/attentive/composite_entity.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Entity

#variable_name

Attributes inherited from Token

#pos

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#==, [], #entity?, register!, #to_s

Methods inherited from Token

#==, #ambiguous?, #entity?, #skippable?, #whitespace?

Constructor Details

#initialize(*args) ⇒ CompositeEntity

Returns a new instance of CompositeEntity.



19
20
21
22
# File 'lib/attentive/composite_entity.rb', line 19

def initialize(*args)
  super
  @entities = self.class.entities.map { |entity_klass| entity_klass.new(variable_name) }
end

Class Attribute Details

.entitiesObject

Returns the value of attribute entities.



9
10
11
# File 'lib/attentive/composite_entity.rb', line 9

def entities
  @entities
end

Instance Attribute Details

#entitiesObject (readonly)

Returns the value of attribute entities.



5
6
7
# File 'lib/attentive/composite_entity.rb', line 5

def entities
  @entities
end

Class Method Details

.define(entity_name, *entities) ⇒ Object



11
12
13
14
15
16
# File 'lib/attentive/composite_entity.rb', line 11

def define(entity_name, *entities)
  entity_klass = Class.new(Attentive::CompositeEntity)
  entity_klass.token_name = entity_name
  entity_klass.entities = entities.map { |entity| Entity[entity] }
  Entity.register! entity_name, entity_klass
end

Instance Method Details

#matches?(cursor) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/attentive/composite_entity.rb', line 24

def matches?(cursor)
  entities.each do |entity|
    match = entity.matches?(cursor.dup)
    return match if match
  end
  false
end