Class: Firebug::Unserializer
- Inherits:
-
Object
- Object
- Firebug::Unserializer
- Defined in:
- lib/firebug/unserializer.rb
Overview
Note:
Hashes will be returned with symbolized keys.
This class will unserialize a PHP serialized string into a ruby object.
Instance Attribute Summary collapse
-
#str ⇒ StringScanner
The current value of str.
Class Method Summary collapse
-
.parse(value) ⇒ Object
Convenience method for unserializing a PHP serialized string.
Instance Method Summary collapse
-
#initialize(string) ⇒ Unserializer
constructor
A new instance of Unserializer.
- #parse ⇒ Object
Constructor Details
#initialize(string) ⇒ Unserializer
Returns a new instance of Unserializer.
15 16 17 |
# File 'lib/firebug/unserializer.rb', line 15 def initialize(string) self.str = StringScanner.new(string) end |
Instance Attribute Details
#str ⇒ StringScanner
Returns the current value of str.
11 12 13 |
# File 'lib/firebug/unserializer.rb', line 11 def str @str end |
Class Method Details
.parse(value) ⇒ Object
Convenience method for unserializing a PHP serialized string.
23 24 25 |
# File 'lib/firebug/unserializer.rb', line 23 def self.parse(value) new(value).parse end |
Instance Method Details
#parse ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/firebug/unserializer.rb', line 28 def parse # rubocop:disable AbcSize,CyclomaticComplexity ch = str.getch return if ch.nil? case ch when 'a' parse_enumerable.tap { expect('}') } when 's' parse_string.tap { expect(';') } when 'i' parse_int.tap { expect(';') } when 'd' parse_double.tap { expect(';') } when 'b' parse_bool.tap { expect(';') } when 'N' expect(';') else raise ParserError, "Unknown token '#{ch}' at position #{str.pos} (#{str.string})" end end |