Class: BEncode::Parser
Instance Attribute Summary collapse
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #eos? ⇒ Boolean
-
#initialize(stream) ⇒ Parser
constructor
A new instance of Parser.
- #parse! ⇒ Object
Constructor Details
#initialize(stream) ⇒ Parser
Returns a new instance of Parser.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/bencode/parser.rb', line 7 def initialize(stream) @stream = if stream.kind_of?(IO) || stream.kind_of?(StringIO) stream elsif stream.respond_to? :string StringIO.new stream.string elsif stream.respond_to? :to_s StringIO.new stream.to_s end @encoding = @stream.external_encoding || Encoding::default_external end |
Instance Attribute Details
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
5 6 7 |
# File 'lib/bencode/parser.rb', line 5 def encoding @encoding end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
5 6 7 |
# File 'lib/bencode/parser.rb', line 5 def stream @stream end |
Instance Method Details
#eos? ⇒ Boolean
28 29 30 |
# File 'lib/bencode/parser.rb', line 28 def eos? stream.eof? end |
#parse! ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/bencode/parser.rb', line 19 def parse! case peek when ?i then parse_integer! when ?l then parse_list! when ?d then parse_dict! when ?0 .. ?9 then parse_string! end end |