Class: ParsedData
- Defined in:
- lib/parsed_data/version.rb,
lib/parsed_data/constants.rb,
lib/parsed_data/parsed_data.rb
Constant Summary collapse
- VERSION =
'0.0.1'- JSON_REGEXP =
/( (?<number> -?(?=[1-9]|0(?!\d))\d+(\.\d+)?([eE][+-]?\d+)?){0} (?<boolean> true | false | null ){0} (?<string> " (?>[^"\\\\]* | \\\\ ["\\\\bfnrt\/] | \\\\ u [0-9a-f]{4} )* " ){0} (?<array> \[ (?> \g<json> (?: , \g<json> )* )? \s* \] ){0} (?<pair> \s* \g<string> \s* : \g<json> ){0} (?<object> \{ (?> \g<pair> (?: , \g<pair> )* )? \s* \} ){0} (?<json> \s* (?> \g<number> | \g<boolean> | \g<string> | \g<array> | \g<object> ) \s* ){0} ) \A \g<json> \Z /uix
- XML_REGEXP =
/[[:space:]]*\<\?xml/
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(data, data_type = nil) ⇒ ParsedData
constructor
A new instance of ParsedData.
- #method_missing(mth, *args, &block) ⇒ Object
Constructor Details
#initialize(data, data_type = nil) ⇒ ParsedData
8 9 10 |
# File 'lib/parsed_data/parsed_data.rb', line 8 def initialize(data, data_type = nil) @source = parse(data) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mth, *args, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/parsed_data/parsed_data.rb', line 12 def method_missing(mth, *args, &block) m = mth.to_s if @source.respond_to? mth process @source.send(mth, *args, &block) elsif m =~ /\S+=/ deep_set(m.gsub(/=/, ''), @source, args[0]) else deep_get(m, @source) end end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
6 7 8 |
# File 'lib/parsed_data/parsed_data.rb', line 6 def source @source end |