Module: Dendroid::GrmAnalysis::ProductionItems

Defined in:
lib/dendroid/grm_analysis/production_items.rb

Overview

Mix-in module for extending the Dendroid::Syntax::Production class with dotted items manipulation methods and an attribute named ‘items`.

Instance Method Summary collapse

Instance Method Details

#build_itemsArray<GrmAnalysis::DottedItem>

Build the dotted items for this production and assign them to the ‘items` attributes

Returns:



13
14
15
16
17
18
19
20
21
# File 'lib/dendroid/grm_analysis/production_items.rb', line 13

def build_items
  @items = if empty?
             [DottedItem.new(self, 0)]
           else
             (0..body.size).reduce([]) do |result, pos|
               result << GrmAnalysis::DottedItem.new(self, pos)
             end
           end
end

#itemsArray<GrmAnalysis::DottedItem>

Read accessor for the ‘items` attribute. Return the dotted items for this production

Returns:



26
27
28
# File 'lib/dendroid/grm_analysis/production_items.rb', line 26

def items
  @items
end

#next_item(anItem) ⇒ GrmAnalysis::DottedItem|NilClass

Return the next item given the provided item. In other words, advance the dot by one position.

Parameters:

Returns:



48
49
50
51
52
# File 'lib/dendroid/grm_analysis/production_items.rb', line 48

def next_item(anItem)
  return nil if anItem == @items.last

  @items[anItem.position + 1]
end

#predicted_itemsArray<GrmAnalysis::DottedItem>

Return the predicted item (i.e. the dotted item with the dot at start) for this production.

Returns:



33
34
35
# File 'lib/dendroid/grm_analysis/production_items.rb', line 33

def predicted_items
  [@items.first]
end

#reduce_itemsArray<GrmAnalysis::DottedItem>

Return the reduce item (i.e. the dotted item with the dot at end) for this production.

Returns:



40
41
42
# File 'lib/dendroid/grm_analysis/production_items.rb', line 40

def reduce_items
  [@items.last]
end