Class: Aspen::Conversion::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/aspen/conversion.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Builder

Returns a new instance of Builder.



8
9
10
11
12
# File 'lib/aspen/conversion.rb', line 8

def initialize(args = {})
  @from_format = args[:format]
  @from_file   = args[:file]
  @csv_options = { headers: true }
end

Instance Method Details

#csv(path) ⇒ Object



14
15
16
17
18
# File 'lib/aspen/conversion.rb', line 14

def csv(path)
  @from_format = :csv
  @from_path   = path
  self
end

#to_aspen(&block) ⇒ Object



27
28
29
30
31
32
33
# 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) ⇒ Object



20
21
22
23
24
25
# File 'lib/aspen/conversion.rb', line 20

def tsv(path)
  @from_format = :csv
  @from_path   = path
  @csv_options[:col_sep] = "\t"
  self
end