Class: PrettyJSON
- Inherits:
-
Object
- Object
- PrettyJSON
- Defined in:
- lib/pretty_json.rb,
lib/pretty_json/version.rb
Overview
Represents a pretty JSON string.
Constant Summary collapse
- VERSION =
'1.0.1'
Instance Method Summary collapse
-
#initialize(input) ⇒ PrettyJSON
constructor
A new instance of PrettyJSON.
-
#to_file(out_file) ⇒ String
Writes pretty formatted JSON to the specified file and returns the same content as a string.
-
#to_s ⇒ String
Pretty formatted JSON.
Constructor Details
#initialize(input) ⇒ PrettyJSON
Returns a new instance of PrettyJSON.
9 10 11 12 |
# File 'lib/pretty_json.rb', line 9 def initialize(input) json_hash = send("#{input.class.name.downcase}_to_hash", input) @json = JSON.pretty_unparse(json_hash) end |
Instance Method Details
#to_file(out_file) ⇒ String
Writes pretty formatted JSON to the specified file and returns the same content as a string.
25 26 27 28 |
# File 'lib/pretty_json.rb', line 25 def to_file(out_file) File.write(out_file, @json) @json end |
#to_s ⇒ String
Returns pretty formatted JSON.
16 17 18 |
# File 'lib/pretty_json.rb', line 16 def to_s @json end |