module RelatonOgc::Scrapper
Constants
- TYPES
Public Class Methods
parse_page(hit)
click to toggle source
papam hit [Hash] @return [RelatonOgc::OrcBibliographicItem]
# File lib/relaton_ogc/scrapper.rb, line 37 def parse_page(hit) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength type = fetch_type(hit["type"]) OgcBibliographicItem.new( fetched: Date.today.to_s, type: "standard", title: fetch_title(hit["title"]), docid: fetch_docid(hit["identifier"]), link: fetch_link(hit["URL"]), doctype: type[:type], subdoctype: type[:subtype], docstatus: fetch_status(type[:stage]), edition: fetch_edition(hit["identifier"]), abstract: fetch_abstract(hit["description"]), contributor: fetch_contributor(hit), language: ["en"], script: ["Latn"], date: fetch_date(hit["date"]), editorialgroup: fetch_editorialgroup, ) end
Private Class Methods
fetch_abstract(description)
click to toggle source
@param description [String] @return [Array<RelatonBib::FormattedString>]
# File lib/relaton_ogc/scrapper.rb, line 103 def fetch_abstract(description) [RelatonBib::FormattedString.new(content: description, language: "en", script: "Latn")] end
fetch_contributor(doc)
click to toggle source
@param doc [Hash] @return [Array<RelatonBib::ContributionInfo>]
# File lib/relaton_ogc/scrapper.rb, line 110 def fetch_contributor(doc) contribs = doc["creator"].to_s.split(", ").map do |name| personn_contrib name end contribs << org_contrib(doc["publisher"]) if doc["publisher"] end
fetch_date(date)
click to toggle source
@param date [String] @return [Array<RelatonBib::BibliographicDate>]
# File lib/relaton_ogc/scrapper.rb, line 140 def fetch_date(date) return [] unless date [RelatonBib::BibliographicDate.new(type: "published", on: date)] end
fetch_docid(identifier)
click to toggle source
@param identifier [String] @return [Array<RelatonBib::DocumentIdentifier>]
# File lib/relaton_ogc/scrapper.rb, line 72 def fetch_docid(identifier) [RelatonBib::DocumentIdentifier.new(id: identifier, type: "OGC")] end
fetch_edition(identifier)
click to toggle source
@param identifier [String] @return [String]
# File lib/relaton_ogc/scrapper.rb, line 96 def fetch_edition(identifier) %r{(?<=r)(?<edition>\d+)$} =~ identifier edition end
fetch_editorialgroup()
click to toggle source
# File lib/relaton_ogc/scrapper.rb, line 60 def fetch_editorialgroup EditorialGroup.new committee: "technical" end
fetch_link(url)
click to toggle source
@param url [String] @return [Array>RelatonBib::TypedUri>]
# File lib/relaton_ogc/scrapper.rb, line 78 def fetch_link(url) [RelatonBib::TypedUri.new(type: "obp", content: url)] end
fetch_status(stage)
click to toggle source
@param stage [String] @return [RelatonBib::DocumentStatus, NilClass]
# File lib/relaton_ogc/scrapper.rb, line 90 def fetch_status(stage) stage && RelatonBib::DocumentStatus.new(stage: stage) end
fetch_title(title)
click to toggle source
@param title [String] @return [Array<RelatonBib::TypedTitleString>]
# File lib/relaton_ogc/scrapper.rb, line 66 def fetch_title(title) RelatonBib::TypedTitleString.from_string title, "en", "Latn" end
fetch_type(type)
click to toggle source
@param type [String] @return [String]
# File lib/relaton_ogc/scrapper.rb, line 84 def fetch_type(type) TYPES[type.sub(/^D-/, "")] || { type: "other" } end
org_contrib(name)
click to toggle source
@param name [String] @return [RelatonBib::ContributionInfo]
# File lib/relaton_ogc/scrapper.rb, line 131 def org_contrib(name) entity = RelatonBib::Organization.new(name: name) RelatonBib::ContributionInfo.new( entity: entity, role: [type: "publisher"], ) end
personn_contrib(name)
click to toggle source
@param name [String] @return [RelatonBib::ContributionInfo]
# File lib/relaton_ogc/scrapper.rb, line 119 def personn_contrib(name) fname = RelatonBib::FullName.new( completename: RelatonBib::LocalizedString.new(name), ) entity = RelatonBib::Person.new(name: fname) RelatonBib::ContributionInfo.new( entity: entity, role: [type: "author"], ) end