Class: CSV2HTML::Conversor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options) ⇒ Conversor

Returns a new instance of Conversor.



13
14
15
16
17
18
# File 'lib/csv2html.rb', line 13

def initialize(data, options)
  parser = CSV.parse(data, headers: true)
  @headers = parser.headers
  @options = options
  @rows = parser
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



11
12
13
# File 'lib/csv2html.rb', line 11

def headers
  @headers
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/csv2html.rb', line 11

def options
  @options
end

#rowsObject (readonly)

Returns the value of attribute rows.



11
12
13
# File 'lib/csv2html.rb', line 11

def rows
  @rows
end

Instance Method Details

#get_bindingObject



20
21
22
# File 'lib/csv2html.rb', line 20

def get_binding
  binding
end

#header_class(options, index) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/csv2html.rb', line 40

def header_class(options, index)
  classes = options[:header_class]
  if classes.nil? || classes[index].nil?
    ''
  else
    " class=\"#{classes[index]}\""
  end
end

#row_class(options, index) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/csv2html.rb', line 31

def row_class(options, index)
  classes = options[:row_class]
  if classes.nil? || classes[index].nil?
    ''
  else
    " class=\"#{classes[index]}\""
  end
end

#tag(name, opts = {}) ⇒ Object



24
25
26
27
28
29
# File 'lib/csv2html.rb', line 24

def tag(name, opts={})
  output = [name]
  output << "class=\"#{opts[:class]}\"" if opts.has_key?(:class)
  output << "id=\"#{opts[:id]}\"" if opts.has_key?(:id)
  "<" + output.join(' ') + ">"
end