Module: Json2yaml
- Defined in:
- lib/json2yaml.rb,
lib/json2yaml/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
Class Method Details
.to_json(yaml_stream, argv) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/json2yaml.rb', line 18 def self.to_json(yaml_stream, argv) inputs = argv.empty? ? [yaml_stream] : argv.map{|file| open(file) } Enumerator.new do |yielder| inputs.each do |input| YAML.load_stream(input) do |d| yielder.yield d.to_json + "\n" end end end end |
.to_yaml(json_stream, argv) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/json2yaml.rb', line 6 def self.to_yaml(json_stream, argv) inputs = argv.empty? ? [json_stream] : argv.map{|file| open(file) } Enumerator.new do |yielder| inputs.each do |input| Yajl::Parser.new.parse(input) do |d| yielder.yield d.to_yaml end end end end |