Class: Mockingjay::Serialize
- Inherits:
-
Object
- Object
- Mockingjay::Serialize
- Defined in:
- lib/mockingjay/serialize.rb
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
-
#initialize(raw_data) ⇒ Serialize
constructor
Parses raw data to JSON.
-
#save_as(name) ⇒ Object
A bit of sugar for quicker saves.
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
#json ⇒ Object (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 |