Class: CSV2HTML::Application

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

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Application

Returns a new instance of Application.



51
52
53
# File 'lib/csv2html.rb', line 51

def initialize(argv)
  @options, @file = parse_options(argv)
end

Instance Method Details

#parse_options(argv) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/csv2html.rb', line 64

def parse_options(argv)
  options = {}
  parser = OptionParser.new

  parser.banner = "Usage: csvtohtml.rb data.csv [options]"

  # Optional argument; Table's ID
  parser.on("-i", "--table-id TABLEID", "Table's ID") do |v|
    options[:id] = v
  end

  # Optional argument; Table's class
  parser.on("-c", "--table-class TABLECLASS", "Table's class") do |v|
    options[:class] = v
  end

  parser.on("-d", "--td-class class1,class2", Array, "Field's classes") do |v|
    options[:row_class] = v
  end

  parser.on("--th-class class1,class2", Array, "Header's classes") do |v|
    options[:header_class] = v
  end

  files = parser.parse(argv)
  [options, files]
end

#runObject



55
56
57
58
59
60
61
62
# File 'lib/csv2html.rb', line 55

def run
  csv_to_html = if @file.empty?
    Conversor.new(STDIN.read, @options)
  else
    Conversor.new(File.read(ARGV[0]), @options)
  end
  print ERB.new(DATA.read).result(csv_to_html.get_binding)
end