Class: CsvTool
- Inherits:
-
Object
- Object
- CsvTool
- Defined in:
- lib/csv_tool.rb,
lib/csv_tool/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
- .convert_to_hash_array(csv_array) ⇒ Object
- .remove_column(csv_hash_array, column_name) ⇒ Object
- .remove_row_with_value(csv_hash_array, column_name, value) ⇒ Object
Class Method Details
.convert_to_hash_array(csv_array) ⇒ Object
4 5 6 7 |
# File 'lib/csv_tool.rb', line 4 def self.convert_to_hash_array(csv_array) fields = csv_array.shift csv_array.collect { |record| Hash[*fields.zip(record).flatten ] } end |
.remove_column(csv_hash_array, column_name) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/csv_tool.rb', line 9 def self.remove_column(csv_hash_array, column_name) csv_hash_array.each do |row| if row.has_key?(column_name) row.delete(column_name) end end end |
.remove_row_with_value(csv_hash_array, column_name, value) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/csv_tool.rb', line 17 def self.remove_row_with_value(csv_hash_array, column_name, value) csv_hash_array.each do |row| if row[column_name] == value csv_hash_array.delete_at(csv_hash_array.index(row)) end end end |