class Zold::JsonPage
JSON page
Public Class Methods
new(text, uri = '')
click to toggle source
# File lib/zold/json_page.rb, line 35 def initialize(text, uri = '') raise 'JSON text can\'t be nil' if text.nil? raise 'JSON must be of type String' unless text.is_a?(String) @text = text @uri = uri end
Public Instance Methods
to_hash()
click to toggle source
# File lib/zold/json_page.rb, line 42 def to_hash raise CantParse, 'JSON is empty, can\'t parse' + (@uri.empty? ? '' : " at #{@uri}") if @text.empty? JSON.parse(@text) rescue JSON::ParserError => e raise CantParse, "Failed to parse JSON #{@uri.empty? ? '' : "at #{@uri}"} (#{short(e.message)}): #{short(@text)}" end
Private Instance Methods
short(txt)
click to toggle source
# File lib/zold/json_page.rb, line 51 def short(txt) txt.gsub(/^.{128,}$/, '\1...').inspect end