Class: Dataset::Adaptors::Iqvoc::AlphabeticalSearchAdaptor
- Inherits:
-
SearchAdaptor
- Object
- SearchAdaptor
- Dataset::Adaptors::Iqvoc::AlphabeticalSearchAdaptor
- Defined in:
- app/models/dataset/adaptors/iqvoc/alphabetical_search_adaptor.rb
Instance Method Summary collapse
- #extract_results(html) ⇒ Object
- #fetch_results(url, params = {}) ⇒ Object
- #search(prefix, locale) ⇒ Object
Instance Method Details
#extract_results(html) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/dataset/adaptors/iqvoc/alphabetical_search_adaptor.rb', line 22 def extract_results(html) @doc = Nokogiri::HTML(html) @doc.css('.concept-item').map do |element| link = element.at_css('.concept-item-link') label, path = link.text, link['data-resource-path'] # href = { definition: element.at_css('.concept-item-definition').try(:content), definition_language: element.at_css('.concept-item-definition').try(:[], :lang), additional_info: element.at_css('.additional_info').try(:content) } result = AlphabeticalSearchResultRemote.new(url, path, label, ) end end |
#fetch_results(url, params = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/dataset/adaptors/iqvoc/alphabetical_search_adaptor.rb', line 7 def fetch_results(url, params = {}) begin response = @conn.get(url, params) @results ||= [] @results += extract_results(response.body) while more = @doc.at_css('a[rel=next]') fetch_results(more[:href], {}) end rescue Faraday::ConnectionFailed, Faraday::ResourceNotFound => e Rails.logger.warn("HTTP error while querying remote source #{url}: #{e.}") return nil end end |
#search(prefix, locale) ⇒ Object
2 3 4 5 |
# File 'app/models/dataset/adaptors/iqvoc/alphabetical_search_adaptor.rb', line 2 def search(prefix, locale) fetch_results("#{locale}/alphabetical_concepts/#{prefix}.html") @results end |