Class: Relaton::Itu::DataFetcher
- Inherits:
-
Core::DataFetcher
- Object
- Core::DataFetcher
- Relaton::Itu::DataFetcher
- Defined in:
- lib/relaton/itu/data_fetcher.rb
Constant Summary collapse
- SEARCH_URL =
"https://www.itu.int/net4/ITU-T/search/GlobalSearch/RunSearch".freeze
- ROWS =
100- MAX_EMPTY_PAGES =
3
Instance Method Summary collapse
- #fetch(_source = nil) ⇒ Object
- #index ⇒ Object
- #to_bibxml(bib) ⇒ Object
- #to_xml(bib) ⇒ Object
- #to_yaml(bib) ⇒ Object
- #write_file(bib) ⇒ Object
Instance Method Details
#fetch(_source = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/relaton/itu/data_fetcher.rb', line 18 def fetch(_source = nil) start = 0 empty_pages = 0 loop do results = search_request(start) if results.empty? empty_pages += 1 break if empty_pages >= MAX_EMPTY_PAGES start += ROWS next end empty_pages = 0 results.each do |result| bib = DataParserR.parse(result) write_file(bib) if bib rescue => e # rubocop:disable Style/RescueStandardError Util.error "#{e.}\n#{e.backtrace}" end start += ROWS end index.save end |
#index ⇒ Object
14 15 16 |
# File 'lib/relaton/itu/data_fetcher.rb', line 14 def index @index ||= Relaton::Index.find_or_create :itu, file: "index-v1.yaml" end |
#to_bibxml(bib) ⇒ Object
65 66 67 |
# File 'lib/relaton/itu/data_fetcher.rb', line 65 def to_bibxml(bib) bib.to_rfcxml end |
#to_xml(bib) ⇒ Object
61 62 63 |
# File 'lib/relaton/itu/data_fetcher.rb', line 61 def to_xml(bib) bib.to_xml bibdata: true end |
#to_yaml(bib) ⇒ Object
57 58 59 |
# File 'lib/relaton/itu/data_fetcher.rb', line 57 def to_yaml(bib) bib.to_yaml end |
#write_file(bib) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/relaton/itu/data_fetcher.rb', line 45 def write_file(bib) # rubocop:disable Metrics/AbcSize id = bib.docidentifier.find(&:primary).content file = output_file(id) if @files.include? file Util.warn "File #{file} exists." else @files << file end index.add_or_update id, file File.write file, serialize(bib), encoding: "UTF-8" end |