Class: CSVConverter
- Inherits:
-
Object
- Object
- CSVConverter
- Defined in:
- lib/csv_converter.rb
Instance Method Summary collapse
- #convert(hash) ⇒ Object
-
#initialize(convert) ⇒ CSVConverter
constructor
A new instance of CSVConverter.
Constructor Details
#initialize(convert) ⇒ CSVConverter
Returns a new instance of CSVConverter.
2 3 4 5 |
# File 'lib/csv_converter.rb', line 2 def initialize(convert) @key = convert.keys.first @conversion = convert[@key] end |
Instance Method Details
#convert(hash) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/csv_converter.rb', line 7 def convert(hash) case @conversion when :integer hash[@key] = hash[@key].to_i when :float hash[@key] = hash[@key].to_f when :string # nop, default else raise ArgumentError.new("Unknown converter: `#{@conversion}`") end hash end |