class Aspen::Conversion::Builder

Public Class Methods

new(args = {}) click to toggle source
# File lib/aspen/conversion.rb, line 8
def initialize(args = {})
  @from_format = args[:format]
  @from_file   = args[:file]
  @csv_options = { headers: true }
end

Public Instance Methods

csv(path) click to toggle source
# File lib/aspen/conversion.rb, line 14
def csv(path)
  @from_format = :csv
  @from_path   = path
  self
end
to_aspen() { |file, aspen| ... } click to toggle source
# File lib/aspen/conversion.rb, line 27
def to_aspen(&block)
  file  = CSV.open(@from_path, @csv_options)
  aspen = File.open(@from_path.rpartition(".").first + ".aspen", 'w')
  yield file, aspen
ensure
  aspen.close
end
tsv(path) click to toggle source
# File lib/aspen/conversion.rb, line 20
def tsv(path)
  @from_format = :csv
  @from_path   = path
  @csv_options[:col_sep] = "\t"
  self
end