Class: Fossyl::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Parser

Returns a new instance of Parser.



6
7
8
# File 'lib/fossyl/parser.rb', line 6

def initialize(string)
  @scanner = StringScanner.new(string)
end

Instance Attribute Details

#scannerObject (readonly)

Returns the value of attribute scanner.



4
5
6
# File 'lib/fossyl/parser.rb', line 4

def scanner
  @scanner
end

Instance Method Details

#parseObject



10
11
12
13
14
15
16
17
# File 'lib/fossyl/parser.rb', line 10

def parse
  return parse_string     if scanner.scan(/\d+/)
  return parse_integer    if scanner.scan(/i/)
  return parse_list       if scanner.scan(/l/)
  return parse_dictionary if scanner.scan(/d/)

  raise Fossyl::InvalidBencoding
end