Class: Bake::Format::NDJSON
- Inherits:
-
Object
- Object
- Bake::Format::NDJSON
- Defined in:
- lib/bake/format/ndjson.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(file) ⇒ NDJSON
constructor
A new instance of NDJSON.
Constructor Details
#initialize(file) ⇒ NDJSON
Returns a new instance of NDJSON.
21 22 23 |
# File 'lib/bake/format/ndjson.rb', line 21 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
25 26 27 |
# File 'lib/bake/format/ndjson.rb', line 25 def file @file end |
Class Method Details
.input(file) ⇒ Object
11 12 13 |
# File 'lib/bake/format/ndjson.rb', line 11 def self.input(file) new(file) end |
.output(file, value) ⇒ Object
15 16 17 18 19 |
# File 'lib/bake/format/ndjson.rb', line 15 def self.output(file, value) value.each do |item| file.puts(JSON.generate(item)) end end |
Instance Method Details
#each ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/bake/format/ndjson.rb', line 27 def each return to_enum unless block_given? @file.each_line do |line| yield JSON.parse(line) end end |