Module: CsvHelper

Included in:
ChinaDistrictCode
Defined in:
lib/china_district_code/helpers/csv_helper.rb

Class Method Summary collapse

Class Method Details

.data_from_csv(name) ⇒ Object

read the data from local csv folder,



16
17
18
# File 'lib/china_district_code/helpers/csv_helper.rb', line 16

def self.data_from_csv(name)
  CSV.read "#{@root_dir}/csv/#{name}.csv"
end

.data_to_csv(name, data) ⇒ Object

array data to csv file,writing file to local csv folder



7
8
9
10
11
12
13
# File 'lib/china_district_code/helpers/csv_helper.rb', line 7

def self.data_to_csv(name,data)
  CSV.open("#{@root_dir}/csv/#{name}.csv", "wb") do |csv|
    data.each do |d|
      csv << d
    end
  end
end