Last active
December 12, 2019 13:51
-
-
Save rodolfopeixoto/ba0fa508329f9ccff5e0c470fa3841f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :add_pure_pilates_in_brazil do | |
desc "Add gyms pure pilates" | |
task start: :environment do | |
@brazil = Country.brazil | |
path = Rails.root.join('lib', 'tasks', 'data', 'pure_pilates_sp_dados.csv') | |
csv_text = File.read(path) | |
csv = CSV.parse(csv_text, headers: true, col_sep: ';', encoding: 'utf-8') | |
gym_group = GymGroup.find_or_create_by(name: 'Pure Pilates', country: @brazil) | |
pilates = Modality.find_by(name: 'pilates') | |
Gym.transaction do | |
csv.each_with_index do |row, index| | |
generate_gym(row, gym_group, pilates, index) | |
end | |
end | |
end | |
end | |
def generate_gym(row, gym_group, pilates, index) | |
acronym = row['id']&.strip | |
address = row['endereco']&.strip | |
cep = row['cep']&.strip | |
city_row = row['cidade']&.strip | |
state = row['estado']&.strip | |
city = State.find_by(uf: state).cities.where("name like ?", city_row).first | |
document_number = row['cnpj']&.strip | |
document_type = 'cnpj' | |
email = "contato.#{acronym.downcase}@purepilates.com.br" | |
neighborhood = row['bairro']&.strip | |
unidade = row['nome']&.strip | |
opening_hours_monday_to_friday = row['Seg-a-Sexta']&.strip | |
opening_hours_on_saturday = row['Sabado']&.strip | |
opening_hours_monday_to_thursday = '' | |
opening_hours_on_friday = '' | |
opening_hours_on_sunday = '' | |
website = 'http://www.purepilates.com.br' | |
company_name = "Pure Pilates #{unidade}" | |
gym_plans = plan_gym(unidade, pilates) | |
gym = Gym.create!( | |
email: email, | |
acronym: acronym, | |
address: address, | |
cep: cep, | |
city: city, | |
company_name: company_name, | |
country_id: @brazil.id, | |
document_number: document_number, | |
document_type: document_type, | |
featured_modality_id: pilates.id, | |
gym_group: gym_group, | |
name: company_name, | |
neighborhood: neighborhood, | |
gym_plans: gym_plans, | |
password: "#{acronym}@totalpass") | |
end | |
def plan_gym(unidade, pilates) | |
# Copays | |
gym_plan_premium = [GymPlan.new(name: 'PREMIUM', price: '199', usage_fee: 10, modalities: [ pilates ])] | |
# Algumas unidades | |
gym_plan_total_new = [GymPlan.new(name: 'TOTAL', price: '299', usage_fee: 10, modalities: [ pilates ])] | |
#Antigos | |
# gym_plans_ultra_old = [GymPlan.new(name: 'ULTRA', price: '349', usage_fee: 10, modalities: [ pilates ])] | |
# gym_plans_total_old = [GymPlan.new(name: 'TOTAL', price: '449', usage_fee: 10, modalities: [ pilates ])] | |
names = [ 'Itaim Bibi', 'Av. Paulista - Brigadeiro', 'Av. Paulista - Consolação', 'Alphaville'] | |
return gym_plan_total_new if names.include? unidade | |
gym_plan_premium | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment