Class: Mokuji::Exporter
- Inherits:
-
Object
- Object
- Mokuji::Exporter
- Includes:
- Validators
- Defined in:
- lib/mokuji/exporter.rb
Overview
{ EXPORTER }
Info
Exports the data to a file
How to use
exporter = Mokuji::Exporter.new exporter.export data_from_converter, export_path
Instance Method Summary collapse
- #export(string, path) ⇒ Object
-
#initialize ⇒ Exporter
constructor
A new instance of Exporter.
Methods included from Validators
#json_valid?, #validate_configuration, #validate_data_from_converter, #validate_data_from_scanner, #validate_export_path, #validate_import_path, validate_options
Constructor Details
#initialize ⇒ Exporter
Returns a new instance of Exporter.
19 20 21 |
# File 'lib/mokuji/exporter.rb', line 19 def initialize validate_configuration end |
Instance Method Details
#export(string, path) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mokuji/exporter.rb', line 23 def export string, path validate_data_from_converter string validate_export_path path data_from_converter = string list_name = (Mokuji::configuration['list_name'] ||= 'Untitled') time = Time.now.strftime('%d_%B_%Y_(%I-%M%p)') file_name = "#{list_name}_-_#{time}" output_type = Mokuji::configuration['output_type'] file_extension = case output_type when 'json' then 'json' when 'html', 'plain_html' then 'html' when 'plain_text' then 'txt' end Dir.chdir(path) File::open("#{file_name}.#{file_extension}", 'w') { |f| f << data_from_converter } end |