Class: Insdc::ImportCountries
- Inherits:
-
Object
- Object
- Insdc::ImportCountries
- Defined in:
- lib/insdc/import_countries.rb
Overview
Handles the download and import of permitted country fields from the ENA
Constant Summary collapse
- FILE_ROOT =
Rails.root.join('data/ena_sample_checklists')
- FIELD_NAME =
'geographic location (country and/or sea)'
- XPATH =
"//FIELD//NAME[text() = '#{FIELD_NAME}']/following-sibling::FIELD_TYPE//TEXT_VALUE//VALUE".freeze
Instance Method Summary collapse
- #download(force: false) ⇒ Object
- #import ⇒ Object
-
#initialize(ena_root:, sample_checklist:, priorities: {}) ⇒ ImportCountries
constructor
A new instance of ImportCountries.
Constructor Details
#initialize(ena_root:, sample_checklist:, priorities: {}) ⇒ ImportCountries
Returns a new instance of ImportCountries.
11 12 13 14 15 |
# File 'lib/insdc/import_countries.rb', line 11 def initialize(ena_root:, sample_checklist:, priorities: {}) @ena_root = ena_root @sample_checklist = sample_checklist @priorities = priorities end |
Instance Method Details
#download(force: false) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/insdc/import_countries.rb', line 17 def download(force: false) return unless force || file_missing? payload = RestClient.get(url).body File.write(file_name, payload) end |
#import ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/insdc/import_countries.rb', line 24 def import no_file_error if file_missing? pending_countries = countries_to_import # Mark countries as invalid if they aren't on the list Insdc::Country.find_each { |country| country.invalid! unless pending_countries.delete(country.name) } generate_countries(pending_countries) end |