Class: Tahweel::Writers::Json
- Inherits:
-
Object
- Object
- Tahweel::Writers::Json
- Defined in:
- lib/tahweel/writers/json.rb
Overview
Writer class for outputting text to a .json file.
Instance Method Summary collapse
-
#extension ⇒ String
Returns the file extension for this writer.
-
#write(texts, destination, options = {}) ⇒ void
Writes the extracted texts to a file.
Instance Method Details
#extension ⇒ String
Returns the file extension for this writer.
12 |
# File 'lib/tahweel/writers/json.rb', line 12 def extension = "json" |
#write(texts, destination, options = {}) ⇒ void
This method returns an undefined value.
Writes the extracted texts to a file.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tahweel/writers/json.rb', line 20 def write(texts, destination, = {}) # rubocop:disable Lint/UnusedMethodArgument structured_data = texts.map.with_index do |text, index| { page: index + 1, content: text.strip } end File.write(destination, JSON.pretty_generate(structured_data)) end |