Class: Firebug::Unserializer
- Inherits:
-
Object
- Object
- Firebug::Unserializer
- Defined in:
- lib/firebug/unserializer.rb
Overview
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 ⇒ Hash, ...
Parse a PHP serialized string into a Ruby object.
Constructor Details
#initialize(string) ⇒ Unserializer
Returns a new instance of Unserializer.
13 14 15 |
# File 'lib/firebug/unserializer.rb', line 13 def initialize(string) self.str = StringScanner.new(string) end |
Instance Attribute Details
#str ⇒ StringScanner
Returns the current value of str.
9 10 11 |
# File 'lib/firebug/unserializer.rb', line 9 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 ⇒ Hash, ...
Note:
Hashes will be returned with symbolized keys.
Parse a PHP serialized string into a Ruby object.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/firebug/unserializer.rb', line 33 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 |