Class: CodeInventory::Source::CSVFile
- Inherits:
-
Object
- Object
- CodeInventory::Source::CSVFile
- Defined in:
- lib/codeinventory/source/csv_file.rb
Instance Attribute Summary collapse
-
#csv ⇒ Object
readonly
Returns the value of attribute csv.
Instance Method Summary collapse
-
#initialize(csv_file) ⇒ CSVFile
constructor
A new instance of CSVFile.
- #projects ⇒ Object
Constructor Details
#initialize(csv_file) ⇒ CSVFile
Returns a new instance of CSVFile.
8 9 10 11 |
# File 'lib/codeinventory/source/csv_file.rb', line 8 def initialize(csv_file) @csv = CSV.read(csv_file, { headers: true, converters: [ :integer ] }) validate_headers end |
Instance Attribute Details
#csv ⇒ Object (readonly)
Returns the value of attribute csv.
6 7 8 |
# File 'lib/codeinventory/source/csv_file.rb', line 6 def csv @csv end |
Instance Method Details
#projects ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/codeinventory/source/csv_file.rb', line 13 def projects @csv.collect do |row| csv_data = row.to_hash csv_data.inject({}) do |memo, pair| csv_header, csv_value = pair case when csv_header == "tags" new_pair = { "tags" => csv_value.split(",").collect { |tag| tag.strip } } when csv_header.include?(".") new_pair = dotted_to_nested(csv_header, csv_value) else new_pair = { csv_header => csv_value } end memo.merge(new_pair) end end end |