Class: Attentive::CompositeEntity
- Defined in:
- lib/attentive/composite_entity.rb
Constant Summary
Constants inherited from Entity
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
#==, [], #_value_from_match, #entity?, #name, #nomatch!, published?, #to_s, undefine
Methods inherited from Token
#==, #ambiguous?, #end, #entity?, #eof?, #inspect, #skippable?, #whitespace?
Constructor Details
#initialize(*args) ⇒ CompositeEntity
Returns a new instance of CompositeEntity.
21 22 23 24 |
# File 'lib/attentive/composite_entity.rb', line 21 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 17 18 |
# File 'lib/attentive/composite_entity.rb', line 11 def define(entity_name, *entities) = entities.last.is_a?(::Hash) ? entities.pop : {} create! entity_name do |entity_klass| entity_klass.entities = entities.map { |entity| Entity[entity] } entity_klass.published = .fetch(:published, true) end end |
Instance Method Details
#matches?(cursor) ⇒ Boolean
26 27 28 29 30 31 32 |
# File 'lib/attentive/composite_entity.rb', line 26 def matches?(cursor) entities.each do |entity| match = entity.matches?(cursor) return match if match end false end |