Class: OOCSV::CSVEntry
- Inherits:
-
Struct
- Object
- Struct
- OOCSV::CSVEntry
- Defined in:
- lib/oocsv.rb
Overview
A struct representing a single line in a CSV file.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ CSVEntry
constructor
Creates a new CSVEntry from a hash, rather than specific symbol => value sets.
-
#to_s ⇒ Object
Returns a string representation of the CSV.
Constructor Details
#initialize(opts = {}) ⇒ CSVEntry
Creates a new CSVEntry from a hash, rather than specific symbol => value sets.
9 10 11 12 13 14 15 16 17 |
# File 'lib/oocsv.rb', line 9 def initialize(opts = {}) opts.each do |k, v| self.class.send(:attr_accessor, k) instance_variable_set("@#{k}", v) end # noinspection RubyInstanceVariableNamingConvention @i_expect_that_nobody_will_use_this_name = opts end |
Instance Method Details
#to_s ⇒ Object
Returns a string representation of the CSV. This is not the same as OOCSV#write.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/oocsv.rb', line 20 def to_s values = {} @i_expect_that_nobody_will_use_this_name.keys.each do |key| val = instance_variable_get("@#{key}") values[key] = val end str = '#<struct Struct::CSVEntry' values.each do |k, v| str << " @#{k}=#{v}" end str << '>' end |