Class: Iiko::CSV

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_to_csv, options = {}) ⇒ CSV

Returns a new instance of CSV.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
# File 'lib/iiko/csv.rb', line 11

def initialize(path_to_csv, options = {})
  @options = { col_sep: ';', quote_char: "\'" }.merge(options)
  @options[:headers] = false

  raise ArgumentError, "'path_to_csv' is required" unless path_to_csv
  @path_to_csv = path_to_csv
end

Instance Attribute Details

#headersObject Also known as: h

Returns the value of attribute headers.



6
7
8
# File 'lib/iiko/csv.rb', line 6

def headers
  @headers
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/iiko/csv.rb', line 6

def options
  @options
end

#path_to_csvObject (readonly)

Returns the value of attribute path_to_csv.



7
8
9
# File 'lib/iiko/csv.rb', line 7

def path_to_csv
  @path_to_csv
end

#rawObject (readonly)

Returns the value of attribute raw.



7
8
9
# File 'lib/iiko/csv.rb', line 7

def raw
  @raw
end

Instance Method Details

#dataObject



25
26
27
# File 'lib/iiko/csv.rb', line 25

def data
  raw[1..-1]
end

#loadObject



19
20
21
22
23
# File 'lib/iiko/csv.rb', line 19

def load
  @raw = ::CSV.read(path_to_csv, options)
  prepare_headers
  self
end