Class: Net::PTTH::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Public: Contructor



9
10
11
12
# File 'lib/net/ptth/parser.rb', line 9

def initialize
  @parser = Http::Parser.new(self)
  reset
end

Instance Attribute Details

#chunkObject (readonly)

Returns the value of attribute chunk.



5
6
7
# File 'lib/net/ptth/parser.rb', line 5

def chunk
  @chunk
end

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/net/ptth/parser.rb', line 5

def headers
  @headers
end

Instance Method Details

#add(data) ⇒ Object Also known as: <<

Public: Adds data to be parsed.

data: string to be parsed


18
19
20
# File 'lib/net/ptth/parser.rb', line 18

def add(data)
  @parser << data
end

#bodyObject

Public: Access the body of the string being parsed



67
68
69
# File 'lib/net/ptth/parser.rb', line 67

def body
  @chunk
end

#body=(chunk) ⇒ Object



71
72
73
# File 'lib/net/ptth/parser.rb', line 71

def body=(chunk)
  @chunk << chunk
end

#finished?Boolean

Public: Internal flag access to know when parsing ended

Returns:

  • (Boolean)


55
# File 'lib/net/ptth/parser.rb', line 55

def finished?; @finished; end

#http_methodObject

Public: Gets the http method parsed



31
32
33
# File 'lib/net/ptth/parser.rb', line 31

def http_method
  @parser.http_method
end

#http_versionObject

Public: Gets the http version parsed



37
38
39
# File 'lib/net/ptth/parser.rb', line 37

def http_version
  @parser.http_version
end

#on_headers_complete(headers) ⇒ Object

Protected: Sets the headers when the parser completes.



77
78
79
# File 'lib/net/ptth/parser.rb', line 77

def on_headers_complete(headers)
  @headers = headers
end

#on_message_beginObject



81
82
83
# File 'lib/net/ptth/parser.rb', line 81

def on_message_begin
  reset
end

#on_message_completeObject

Protected: Flags the parsing as ended



87
88
89
# File 'lib/net/ptth/parser.rb', line 87

def on_message_complete
  @finished = true
end

#resetObject

Public: Resets the parser internal flags



59
60
61
62
63
# File 'lib/net/ptth/parser.rb', line 59

def reset
  @finished = false
  @headers  = nil
  @chunk    = ""
end

#status_codeObject

Public: Gets the status code parsed



43
44
45
# File 'lib/net/ptth/parser.rb', line 43

def status_code
  @parser.status_code
end

#upgrade?Boolean

Public: Check for an upgrade header in the parsed string

Returns:

  • (Boolean)


25
26
27
# File 'lib/net/ptth/parser.rb', line 25

def upgrade?
  @parser.upgrade?
end

#urlObject

Public: Gets the url parsed



49
50
51
# File 'lib/net/ptth/parser.rb', line 49

def url
  @parser.request_url
end