Class: Pacer::Transform::CountSection::CountSectionPipe

Inherits:
Pipes::RubyPipe
  • Object
show all
Defined in:
lib/pacer/transform/count_section.rb

Instance Attribute Summary collapse

Attributes inherited from Pipes::RubyPipe

#starts

Instance Method Summary collapse

Methods inherited from Pipes::RubyPipe

#enablePath, #reset, #setStarts

Constructor Details

#initialize(section, pipe_function) ⇒ CountSectionPipe

Returns a new instance of CountSectionPipe.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pacer/transform/count_section.rb', line 35

def initialize(section, pipe_function)
  super()
  @count = 0
  @section = section
  if section
    section.visitor = self
  else
    on_element nil
  end
  @pf = pipe_function
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



33
34
35
# File 'lib/pacer/transform/count_section.rb', line 33

def count
  @count
end

#pfObject (readonly)

Returns the value of attribute pf.



33
34
35
# File 'lib/pacer/transform/count_section.rb', line 33

def pf
  @pf
end

#sectionObject (readonly)

Returns the value of attribute section.



33
34
35
# File 'lib/pacer/transform/count_section.rb', line 33

def section
  @section
end

#section_keyObject (readonly)

Returns the value of attribute section_key.



33
34
35
# File 'lib/pacer/transform/count_section.rb', line 33

def section_key
  @section_key
end

#to_emitObject (readonly)

Returns the value of attribute to_emit.



33
34
35
# File 'lib/pacer/transform/count_section.rb', line 33

def to_emit
  @to_emit
end

Instance Method Details

#after_elementObject



73
74
75
76
# File 'lib/pacer/transform/count_section.rb', line 73

def after_element
  @to_emit = [section_key, count]
  @count = 0
end

#getPathToHereObject



65
66
67
# File 'lib/pacer/transform/count_section.rb', line 65

def getPathToHere
  section.getCurrentPath
end

#on_element(element) ⇒ Object



69
70
71
# File 'lib/pacer/transform/count_section.rb', line 69

def on_element(element)
  @section_key = pf.compute element
end

#processNextStartObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pacer/transform/count_section.rb', line 47

def processNextStart
  until to_emit
    starts.next
    @count += 1
  end
  raise EmptyPipe.instance if to_emit.empty?
  emit = to_emit
  @to_emit = nil
  emit
rescue EmptyPipe, java.util.NoSuchElementException
  if count == 0
    raise EmptyPipe.instance
  else
    after_element
    to_emit
  end
end