Class: GQTP::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/gqtp/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



87
88
89
90
# File 'lib/gqtp/parser.rb', line 87

def initialize
  reset
  initialize_hooks
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



86
87
88
# File 'lib/gqtp/parser.rb', line 86

def header
  @header
end

Class Method Details

.parse(data, &block) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/gqtp/parser.rb', line 28

def parse(data, &block)
  if block_given?
    event_parse(data, &block)
  else
    stand_alone_parse(data)
  end
end

Instance Method Details

#<<(chunk) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/gqtp/parser.rb', line 92

def <<(chunk)
  if @header.nil?
    parse_header(chunk)
  else
    parse_body(chunk)
  end
  self
end

#on_body(chunk) ⇒ Object #on_body({|chunk| }) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/gqtp/parser.rb', line 113

def on_body(*arguments, &block)
  if block_given?
    @on_body_hook = block
  else
    @on_body_hook.call(*arguments) if @on_body_hook
  end
end

#on_completeObject #on_complete({ }) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/gqtp/parser.rb', line 123

def on_complete(&block)
  if block_given?
    @on_complete_hook = block
  else
    @on_complete_hook.call if @on_complete_hook
  end
end

#on_header(header) ⇒ Object #on_header({|header| }) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/gqtp/parser.rb', line 103

def on_header(*arguments, &block)
  if block_given?
    @on_header_hook = block
  else
    @on_header_hook.call(*arguments) if @on_header_hook
  end
end