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.



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

def initialize
  reset
  initialize_hooks
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



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

def header
  @header
end

Class Method Details

.parse(data, &block) ⇒ Object



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

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

Instance Method Details

#<<(chunk) ⇒ Object



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

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

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



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

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



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

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



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

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