Class: 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.



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

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

Instance Attribute Details

#scannerObject (readonly)

Returns the value of attribute scanner.



2
3
4
# File 'lib/fossyl/parser.rb', line 2

def scanner
  @scanner
end

Instance Method Details

#parseObject



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

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