Skip to content

Commit 9146a55

Browse files
committed
Fixed ericduran#9 Rewrote companies.rb to find the company names in more varied situations
1 parent 9779549 commit 9146a55

File tree

3 files changed

+2667
-4291
lines changed

3 files changed

+2667
-4291
lines changed

companies.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
COMPANY_NOT_DEFINED='not_defined'
1111
UPDATE_NONE=0
1212
UPDATE_NOT_FOUND=1
13-
UPDATE_ALL=1
13+
UPDATE_ALL=2
1414

1515
name_mappings = YAML::load_file('./name_mappings.yml')
1616
$companies_info = YAML::load_file('./company_infos.yml') || Hash.new(0)
@@ -104,15 +104,24 @@ def ensure_company(companies, key, title, link)
104104
found = false
105105
if company_wrapper = doc.at_css('.field-name-field-organization-name')
106106
if company_wrapper.at_css('img')
107+
company = company_wrapper.at_css('img')['alt']
108+
else
109+
company = company_wrapper.text
110+
end
111+
if company_wrapper.at_css('a')
107112
link = company_wrapper.at_css('a')
108113
link['href'] = 'https://drupal.org' + link['href']
109-
html = open(link['href'], :allow_redirections => :safe)
110-
company_page = Nokogiri::HTML(html)
111-
if company_title = company_page.at_css('#page-subtitle')
112-
company = company_title.text
114+
# If we still don't have the company name, follow the link to the page.
115+
unless company
116+
html = open(link['href'], :allow_redirections => :safe)
117+
company_page = Nokogiri::HTML(html)
118+
if company_title = company_page.at_css('#page-subtitle')
119+
company = company_title.text
120+
end
113121
end
114122
else
115-
company = company_wrapper.text
123+
# If there is no link, use the company name instead.
124+
link = company
116125
end
117126
company = company.strip
118127
company_key = company.downcase

0 commit comments

Comments
 (0)