Class: Food
- Inherits:
-
Object
- Object
- Food
- Defined in:
- lib/data/sr24/csv_to_muchidata.rb
Instance Method Summary collapse
- #build_hash ⇒ Object
- #category ⇒ Object
- #hash ⇒ Object
-
#initialize ⇒ Food
constructor
A new instance of Food.
- #names ⇒ Object
- #number ⇒ Object
Constructor Details
#initialize ⇒ Food
Returns a new instance of Food.
44 45 46 47 |
# File 'lib/data/sr24/csv_to_muchidata.rb', line 44 def initialize @hash = Hash.new build_hash end |
Instance Method Details
#build_hash ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/data/sr24/csv_to_muchidata.rb', line 54 def build_hash CSV.read("FOOD_DES.csv").each do |line| rows = line puts rows.inspect number = rows.first.split("^").first category = rows[0].split("^")[1] name = rows.first.split("^").last begin if rows.size >= 2 todo = rows[1] + rows[2] + rows[3] name = name + todo end rescue TypeError end name = name.gsub(/\d/,' ').gsub("^", ' ').gsub(".", '') @hash[number] = [name, category] end end |
#category ⇒ Object
89 90 91 |
# File 'lib/data/sr24/csv_to_muchidata.rb', line 89 def category @hash.values.map{|f| f[1] } end |
#hash ⇒ Object
50 51 52 |
# File 'lib/data/sr24/csv_to_muchidata.rb', line 50 def hash @hash end |
#names ⇒ Object
81 82 83 |
# File 'lib/data/sr24/csv_to_muchidata.rb', line 81 def names @hash.values.map{ |f| f[0] } end |
#number ⇒ Object
85 86 87 |
# File 'lib/data/sr24/csv_to_muchidata.rb', line 85 def number @hash.keys end |