Class: Attentive::CompositeEntity
- Defined in:
- lib/attentive/composite_entity.rb
Class Attribute Summary collapse
-
.entities ⇒ Object
Returns the value of attribute entities.
Instance Attribute Summary collapse
-
#entities ⇒ Object
readonly
Returns the value of attribute entities.
Attributes inherited from Entity
Attributes inherited from Token
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ CompositeEntity
constructor
A new instance of CompositeEntity.
- #matches?(cursor) ⇒ Boolean
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
.entities ⇒ Object
Returns the value of attribute entities.
9 10 11 |
# File 'lib/attentive/composite_entity.rb', line 9 def entities @entities end |
Instance Attribute Details
#entities ⇒ Object (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
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 |