Class: Zold::JsonPage
- Inherits:
-
Object
- Object
- Zold::JsonPage
- Defined in:
- lib/zold/json_page.rb
Overview
JSON page
Instance Method Summary collapse
-
#initialize(text) ⇒ JsonPage
constructor
A new instance of JsonPage.
- #to_hash ⇒ Object
Constructor Details
#initialize(text) ⇒ JsonPage
Returns a new instance of JsonPage.
30 31 32 33 34 |
# File 'lib/zold/json_page.rb', line 30 def initialize(text) raise 'JSON text can\'t be nil' if text.nil? raise 'JSON must be of type String' unless text.is_a?(String) @text = text end |
Instance Method Details
#to_hash ⇒ Object
36 37 38 39 40 41 |
# File 'lib/zold/json_page.rb', line 36 def to_hash raise 'JSON is empty, can\'t parse' if @text.empty? JSON.parse(@text) rescue JSON::ParserError => e raise "Failed to parse JSON (#{e.}): #{@text}" end |