Class: Klipbook::Commands::ToJson

Inherits:
Object
  • Object
show all
Defined in:
lib/klipbook/commands/tojson.rb

Instance Method Summary collapse

Constructor Details

#initialize(books, book_file) ⇒ ToJson

Returns a new instance of ToJson.



3
4
5
6
# File 'lib/klipbook/commands/tojson.rb', line 3

def initialize(books, book_file)
  @books = books
  @book_file = book_file
end

Instance Method Details

#call(output_file_path, force, message_stream = $stdout) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/klipbook/commands/tojson.rb', line 8

def call(output_file_path, force, message_stream=$stdout)
  message_stream.puts "\nWriting book json to file: #{output_file_path}"

  @book_file.add_books(@books, force)

  File.open(output_file_path, 'w') do |output_file|
    output_file.puts @book_file.to_json
  end
end