Class: JSON::Pie::TopLevel
- Inherits:
-
Object
- Object
- JSON::Pie::TopLevel
- Defined in:
- lib/json/pie/top_level.rb
Instance Attribute Summary collapse
-
#instance ⇒ Object
Returns the value of attribute instance.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ TopLevel
constructor
A new instance of TopLevel.
- #parse(**options) ⇒ Object
Constructor Details
#initialize(params) ⇒ TopLevel
Returns a new instance of TopLevel.
14 15 16 17 |
# File 'lib/json/pie/top_level.rb', line 14 def initialize(params) params = params.permit!.to_h.deep_symbolize_keys if params.respond_to?(:permit!) @params = params end |
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
8 9 10 |
# File 'lib/json/pie/top_level.rb', line 8 def instance @instance end |
Class Method Details
.parse(params, **options) ⇒ Object
10 11 12 |
# File 'lib/json/pie/top_level.rb', line 10 def self.parse(params, **) new(params).tap { |i| i.parse(**) }.instance end |
Instance Method Details
#parse(**options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/json/pie/top_level.rb', line 19 def parse(**) = data = params.fetch(:data) self.instance = case data when Array then parse_as_array else parse_as_object end rescue StandardError => error raise JSON::Pie::MalformattedDataObject, "malformmated data structure" end |