Module: Dendroid::GrmAnalysis::ChoiceItems
- Defined in:
- lib/dendroid/grm_analysis/choice_items.rb
Overview
Mix-in module for extending the Syntax::Choice class with dotted items manipulation methods
Instance Method Summary collapse
-
#build_items ⇒ Array<Array<GrmAnalysis::AlternativeItem>>
Build the alternative items for this choice and assign them to the ‘items` attributes.
-
#items ⇒ Array<Array<GrmAnalysis::AlternativeItem>>
Read accessor for the ‘items` attribute.
-
#next_item(anItem) ⇒ GrmAnalysis::AlternativeItem|NilClass
Return the next item given the provided item.
-
#predicted_items ⇒ Array<GrmAnalysis::AlternativeItem>
Return the predicted items (i.e. the alternative items with the dot at start) for this choice.
-
#reduce_items ⇒ Array<GrmAnalysis::AlternativeItem>
Return the reduce items (i.e. the alternative items with the dot at end) for this choice.
Instance Method Details
#build_items ⇒ Array<Array<GrmAnalysis::AlternativeItem>>
Build the alternative items for this choice and assign them to the ‘items` attributes
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dendroid/grm_analysis/choice_items.rb', line 13 def build_items # AlternativeItem @items = Array.new(alternatives.size) { |_| [] } alternatives.each_with_index do |alt_seq, index| if alt_seq.empty? @items[index] << AlternativeItem.new(self, 0, index) else (0..alt_seq.size).each do |pos| @items[index] << AlternativeItem.new(self, pos, index) end end end end |
#items ⇒ Array<Array<GrmAnalysis::AlternativeItem>>
Read accessor for the ‘items` attribute. Return the dotted items for this production
30 31 32 |
# File 'lib/dendroid/grm_analysis/choice_items.rb', line 30 def items @items end |
#next_item(anItem) ⇒ GrmAnalysis::AlternativeItem|NilClass
Return the next item given the provided item. In other words, advance the dot by one position.
52 53 54 55 56 57 |
# File 'lib/dendroid/grm_analysis/choice_items.rb', line 52 def next_item(anItem) items_arr = items[anItem.alt_index] return nil if anItem == items_arr.last items_arr[anItem.position + 1] end |
#predicted_items ⇒ Array<GrmAnalysis::AlternativeItem>
Return the predicted items (i.e. the alternative items with the dot at start) for this choice.
37 38 39 |
# File 'lib/dendroid/grm_analysis/choice_items.rb', line 37 def predicted_items @items.map(&:first) end |
#reduce_items ⇒ Array<GrmAnalysis::AlternativeItem>
Return the reduce items (i.e. the alternative items with the dot at end) for this choice.
44 45 46 |
# File 'lib/dendroid/grm_analysis/choice_items.rb', line 44 def reduce_items @items.map(&:last) end |