Class: Relaton::Xsf::DataFetcher
- Inherits:
-
Core::DataFetcher
- Object
- Core::DataFetcher
- Relaton::Xsf::DataFetcher
- Defined in:
- lib/relaton/xsf/data_fetcher.rb
Instance Method Summary collapse
- #fetch(_source = nil) ⇒ Object
- #index ⇒ Object
- #save_doc(bib) ⇒ Object
- #to_bibxml(bib) ⇒ Object
- #to_xml(bib) ⇒ Object
- #to_yaml(bib) ⇒ Object
Instance Method Details
#fetch(_source = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/relaton/xsf/data_fetcher.rb', line 10 def fetch(_source = nil) agent = Mechanize.new resp = agent.get "https://xmpp.org/extensions/refs/" resp.xpath("//a[contains(@href, 'XEP-')]").each do |link| doc = agent.get link[:href] bib = Relaton::Bib::Converter::BibXml.to_item doc.body save_doc bib rescue StandardError => e Util.warn "Failed to parse #{link[:href]}: #{e.}" end index.save end |
#index ⇒ Object
6 7 8 |
# File 'lib/relaton/xsf/data_fetcher.rb', line 6 def index @index ||= Relaton::Index.find_or_create :xsf, file: "#{INDEXFILE}.yaml" end |
#save_doc(bib) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/relaton/xsf/data_fetcher.rb', line 23 def save_doc(bib) return unless bib bib.ext ||= Relaton::Bib::Ext.new bib.ext.flavor = "xsf" docid = bib.docidentifier.detect(&:primary) || bib.docidentifier.first id = docid&.content return unless id file = output_file id if @files.include? file Util.warn "File #{file} already exists" else @files << file end File.write file, serialize(bib), encoding: "UTF-8" index.add_or_update id, file end |
#to_bibxml(bib) ⇒ Object
51 52 53 |
# File 'lib/relaton/xsf/data_fetcher.rb', line 51 def to_bibxml(bib) bib.to_rfcxml end |
#to_xml(bib) ⇒ Object
47 48 49 |
# File 'lib/relaton/xsf/data_fetcher.rb', line 47 def to_xml(bib) bib.to_xml bibdata: true end |
#to_yaml(bib) ⇒ Object
43 44 45 |
# File 'lib/relaton/xsf/data_fetcher.rb', line 43 def to_yaml(bib) bib.to_yaml end |