Class: Wuclan::JsonModel::GenericJsonParser

Inherits:
Object
  • Object
show all
Defined in:
lib/wuclan/twitter/parse/generic_json_parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ GenericJsonParser

Returns a new instance of GenericJsonParser.



5
6
7
# File 'lib/wuclan/twitter/parse/generic_json_parser.rb', line 5

def initialize raw
  self.raw = raw
end

Instance Attribute Details

#rawObject

Returns the value of attribute raw.



4
5
6
# File 'lib/wuclan/twitter/parse/generic_json_parser.rb', line 4

def raw
  @raw
end

Class Method Details

.new_from_json(json_str, *args) ⇒ Object

Safely parse the json object and instantiate with the raw hash



13
14
15
16
17
18
19
20
21
22
# File 'lib/wuclan/twitter/parse/generic_json_parser.rb', line 13

def self.new_from_json json_str, *args
  return unless json_str
  begin
    raw = JSON.load(json_str) or return
  rescue Exception => e;
    warn e
    return
  end
  self.new raw, *args
end

Instance Method Details

#healthy?Boolean

Returns:

  • (Boolean)


8
# File 'lib/wuclan/twitter/parse/generic_json_parser.rb', line 8

def healthy?() raw && raw.is_a?(Hash) end