module RicoJSON
Main RicoJSON
functionality
Public Class Methods
open(json)
click to toggle source
# File lib/ricojson.rb, line 9 def self.open(json) `xdg-open #{json.path}` end
open_in_file(body)
click to toggle source
Used to open the prettified JSON in a text editor or other system's app
# File lib/ricojson.rb, line 58 def self.open_in_file(body) fork do json = Tempfile.new(['json', '.json']) json.write(body) json.close open(json) end end
read_file(filename, open = false)
click to toggle source
Method for reading a file as an input
Example:
$ ricojson -f comics.json
Arguments:
filename: Name of the input file open: Open the file in the default app/text editor for ,json
files (optional)
Returns:¶ ↑
JSON Rico y Suave
# File lib/ricojson.rb, line 30 def self.read_file(filename, open = false) read_string(File.read(filename), open) end
read_string(json_string, open = false)
click to toggle source
Method for reading a String as an input
Example:
$ cat comics.json | ricojson
Arguments:
json_string: Incoming String (could be piped from curl, cat, echo, etc) open: Open the file in the default app/text editor for ,json
files (optional)
Returns:¶ ↑
JSON Rico y Suave
# File lib/ricojson.rb, line 47 def self.read_string(json_string, open = false) body = JSON.pretty_generate(JSON.parse(json_string)) if open open_in_file(body) else puts body end end