class Taxonifi::Export::Base

All export classes inherit from Taxonifi::Export::Base

Constants

EXPORT_BASE

Attributes

base_export_path[RW]
export_folder[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/export/format/base.rb, line 8
def initialize(options = {})
  opts = {
    :base_export_path => EXPORT_BASE,
    :export_folder => '.'
  }.merge!(options)

  @base_export_path = opts[:base_export_path]  
  @export_folder = opts[:export_folder] 
end

Public Instance Methods

configure_folders() click to toggle source

Recursively (over)write the the export path.

# File lib/export/format/base.rb, line 30
def configure_folders
  FileUtils.mkdir_p export_path
end
export() click to toggle source

Subclassed models expand on this method, typically writing files to the folders created here.

# File lib/export/format/base.rb, line 25
def export
  configure_folders
end
export_path() click to toggle source

Return the path to which exported files will be written.

# File lib/export/format/base.rb, line 19
def export_path
  File.expand_path(File.join(@base_export_path, @export_folder))
end
write_file(filename = 'foo', string = nil) click to toggle source

Write the string to a file in the export path.

# File lib/export/format/base.rb, line 35
def write_file(filename = 'foo', string = nil)
  raise ExportError, 'Nothing to export for #{filename}.' if string.nil? || string == ""
  f = File.new( File.expand_path(File.join(export_path, filename)), 'w+')
  f.puts string
  f.close
end