Class: Mockingjay::Serialize

Inherits:
Object
  • Object
show all
Defined in:
lib/mockingjay/serialize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data) ⇒ Serialize

Parses raw data to JSON



6
7
8
# File 'lib/mockingjay/serialize.rb', line 6

def initialize(raw_data)
  @json = reduce_hash(raw_data.is_a?(Hash) ? raw_data : JSON.parse(raw_data)).to_json
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



3
4
5
# File 'lib/mockingjay/serialize.rb', line 3

def json
  @json
end

Instance Method Details

#save_as(name) ⇒ Object

A bit of sugar for quicker saves



11
12
13
# File 'lib/mockingjay/serialize.rb', line 11

def save_as(name)
  File.open("#{name}.json", 'w') { |file| file.write @json }
end