Class: CSVRow
- Inherits:
-
Object
- Object
- CSVRow
- Defined in:
- lib/csvgen.rb
Instance Method Summary collapse
- #[]=(idx, val) ⇒ Object
- #col(*args) ⇒ Object
-
#initialize(file) ⇒ CSVRow
constructor
A new instance of CSVRow.
- #length=(n) ⇒ Object
- #skip(n) ⇒ Object
- #to_s ⇒ Object
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_s ⇒ Object
73 74 75 |
# File 'lib/csvgen.rb', line 73 def to_s @cols.collect { |c| @file.enquote(c) }.join(@file.sep) end |