Skip to content

Commit

Permalink
Removed use of globals in companies.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Cambra committed Feb 23, 2015
1 parent a098587 commit 707aff2
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions app/bin/companies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

name_variants = Hash.new(0)
if File.exists? ('../data/company_infos.yml')
$companies_info = YAML::load_file('../data/company_infos.yml')
companies_info = YAML::load_file('../data/company_infos.yml')
else
$companies_info = Hash.new(0)
companies_info = Hash.new(0)
end
if File.exists? ('../data/company_mapping.yml')
company_mapping = YAML::load_file('../data/company_mapping.yml') || Hash.new(0)
Expand All @@ -44,13 +44,13 @@
contributors = data['contributors']
companies = Hash.new(0)

def ensure_company(companies, key, title, link)
def ensure_company(companies, companies_info, key, title, link)
unless companies.key? key
companies[key] = Hash.new(0)
companies[key]['contributors'] = Hash.new(0)
if $companies_info.key? key
companies[key]['title'] = $companies_info[key]['title']
companies[key]['link'] = $companies_info[key]['link']
if companies_info.key? key
companies[key]['title'] = companies_info[key]['title']
companies[key]['link'] = companies_info[key]['link']
else
companies[key]['title'] = title
companies[key]['link'] = link
Expand All @@ -61,7 +61,7 @@ def ensure_company(companies, key, title, link)
contributors.sort_by {|k, v| v }.reverse.each do |name,mentions|
if company_mapping.key? name
if update == UPDATE_NONE or (update == UPDATE_NOT_FOUND and company_mapping[name] != COMPANY_NOT_FOUND)
ensure_company(companies, company_mapping[name], 'should be filled via company infos', 'should be filled via company infos')
ensure_company(companies, companies_info, company_mapping[name], 'should be filled via company infos', 'should be filled via company infos')
companies[company_mapping[name]]['mentions'] += mentions
companies[company_mapping[name]]['contributors'][name] = mentions
next
Expand All @@ -87,7 +87,7 @@ def ensure_company(companies, key, title, link)
end
end
unless found
ensure_company(companies, COMPANY_NOT_FOUND, 'Users not found', 'Users not found')
ensure_company(companies, companies_info, COMPANY_NOT_FOUND, 'Users not found', 'Users not found')
companies[COMPANY_NOT_FOUND]['mentions'] += mentions
companies[COMPANY_NOT_FOUND]['contributors'][name] = mentions
end
Expand Down Expand Up @@ -116,13 +116,13 @@ def ensure_company(companies, key, title, link)
end
company = company.strip
company_key = company.downcase
ensure_company(companies, company_key, company, link.to_s)
ensure_company(companies, companies_info, company_key, company, link.to_s)
companies[company_key]['mentions'] += mentions
companies[company_key]['contributors'][name] = mentions
found = true
end
unless found
ensure_company(companies, COMPANY_NOT_DEFINED, 'Not specified', 'Not specified')
ensure_company(companies, companies_info, COMPANY_NOT_DEFINED, 'Not specified', 'Not specified')
companies[COMPANY_NOT_DEFINED]['mentions'] += mentions
companies[COMPANY_NOT_DEFINED]['contributors'][name] = mentions
end
Expand All @@ -131,19 +131,19 @@ def ensure_company(companies, key, title, link)

companies = companies.sort_by {|k, v| v['mentions'] }.reverse
companies.each do |k, values|
unless $companies_info.key? k
$companies_info[k] = Hash.new(0)
$companies_info[k]['title'] = values['title']
$companies_info[k]['link'] = values['link']
unless companies_info.key? k
companies_info[k] = Hash.new(0)
companies_info[k]['title'] = values['title']
companies_info[k]['link'] = values['link']
end
values['contributors'].each do |name, mentions|
company_mapping[name] = k
end
if values['contributors'].length == 0
$companies_info.delete(k)
companies_info.delete(k)
end
end
File.open('../data/company_infos.yml', 'w') { |f| YAML.dump($companies_info, f) }
File.open('../data/company_infos.yml', 'w') { |f| YAML.dump(companies_info, f) }
File.open('../data/company_mapping.yml', 'w') { |f| YAML.dump(company_mapping, f) }

sum = contributors.values.reduce(:+).to_f
Expand Down

0 comments on commit 707aff2

Please sign in to comment.