Class: Parsed::ParsesJson

Inherits:
Struct
  • Object
show all
Defined in:
lib/parsed/parses_json.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



4
5
6
# File 'lib/parsed/parses_json.rb', line 4

def data
  @data
end

Class Method Details

.parse(data) ⇒ Object



6
7
8
9
10
# File 'lib/parsed/parses_json.rb', line 6

def self.parse(data)
  return data if data.instance_of? Hash

  JSON.parse(data, { :symbolize_names => true })
end

.parse_elements(data, field) ⇒ Object



16
17
18
# File 'lib/parsed/parses_json.rb', line 16

def self.parse_elements(data, field)
  data[field.to_sym] || []
end

.parse_value(data, field) ⇒ Object



12
13
14
# File 'lib/parsed/parses_json.rb', line 12

def self.parse_value(data, field)
  data[field.to_sym]
end