Module: Helper
- Included in:
- Challenge::Solution
- Defined in:
- lib/helper.rb
Instance Method Summary collapse
- #export_data(file_name, deliverables) ⇒ Object
- #import_capacities_data(file_name) ⇒ Object
- #import_partners_data(file_name) ⇒ Object
- #import_theatres_data(file_name) ⇒ Object
- #read_data(file_name, have_headers = true) ⇒ Object
Instance Method Details
#export_data(file_name, deliverables) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/helper.rb', line 12 def export_data(file_name, deliverables) CSV.open(file_name, "wb", headers: false) do |row| deliverables.each do |deliverable| row << [deliverable.delivery_id, deliverable.is_deliverable, deliverable.partner_id, deliverable.delivery_cost] end end end |
#import_capacities_data(file_name) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/helper.rb', line 20 def import_capacities_data(file_name) capacities_data = read_data(file_name) capacities = {} capacities_data.each do |capacity_data| capacities[capacity_data[0].strip] = capacity_data[1].strip.to_i end capacities end |
#import_partners_data(file_name) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/helper.rb', line 29 def import_partners_data(file_name) partners_data = read_data(file_name) partners = [] partners_data.each do |partner_data| slabs = partner_data[1].strip.split('-') partners << Partner.new(partner_data[0].strip, slabs.first.to_i, slabs.last.to_i, partner_data[2].strip.to_i, partner_data[3].strip.to_i, partner_data[4].strip) end partners end |
#import_theatres_data(file_name) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/helper.rb', line 39 def import_theatres_data(file_name) theatres_data = read_data(file_name, false) theatres = [] theatres_data.each do |theatre_data| theatres << Theatre.new(theatre_data[0].strip, theatre_data[1].strip.to_i, theatre_data[2].strip ) end theatres end |
#read_data(file_name, have_headers = true) ⇒ Object
6 7 8 9 10 |
# File 'lib/helper.rb', line 6 def read_data(file_name, have_headers=true) csv_text = File.read(file_name) csv_data = CSV.parse(csv_text, headers: have_headers) csv_data end |