Class: CSVRow

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

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ CSVRow

Returns a new instance of CSVRow.



53
54
55
56
# File 'lib/csvgen.rb', line 53

def initialize(file)
  @file = file
  @cols = []
end

Instance Method Details

#[]=(idx, val) ⇒ Object



69
70
71
# File 'lib/csvgen.rb', line 69

def []=(idx, val)
  @cols[idx] = val
end

#col(*args) ⇒ Object



58
59
60
61
62
63
# File 'lib/csvgen.rb', line 58

def col(*args)
  val = args[0]
  opts = args[1] || {:quote => true}
  @cols.push(val)
  self
end

#length=(n) ⇒ Object



65
66
67
# File 'lib/csvgen.rb', line 65

def length=(n)
  @cols = (0..(n - 1)).map { |idx| @cols[idx] || nil }
end

#skip(n) ⇒ Object



77
78
79
80
81
# File 'lib/csvgen.rb', line 77

def skip(n)
  n.times do |nn|
    col(nil)
  end
end

#to_sObject



73
74
75
# File 'lib/csvgen.rb', line 73

def to_s
  @cols.collect { |c| @file.enquote(c) }.join(@file.sep)
end