Class: Relaton::Itu::RadioRegulationsParser

Inherits:
Object
  • Object
show all
Includes:
Core::ArrayWrapper
Defined in:
lib/relaton/itu/radio_regulations_parser.rb

Constant Summary collapse

ROMAN_MONTHS =
%w[I II III IV V VI VII VIII IX X XI XII].freeze

Instance Method Summary collapse

Constructor Details

#initialize(hit) ⇒ RadioRegulationsParser

Returns a new instance of RadioRegulationsParser.



10
11
12
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 10

def initialize(hit)
  @hit = hit
end

Instance Method Details

#docObject



14
15
16
17
18
19
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 14

def doc
  @doc ||= hit.hit_collection.agent.get doc_url
rescue Mechanize::ResponseCodeError, SocketError, Timeout::Error, Errno::ECONNRESET,
        EOFError, Net::ProtocolError, OpenSSL::SSL::SSLError => e
  raise Relaton::RequestError, "Could not access #{doc_url}: #{e.message}"
end

#doc_dateObject



44
45
46
47
48
49
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 44

def doc_date
  return @doc_date if defined? @doc_date

  date_str = doc.at("//td[@class='title']/text()")&.text&.slice(/(?<=Year:\s)(?:\d{1,2}\.\w+\.)?\d{4}/)
  @doc_date = date_str ? roman_to_arabic(date_str) : nil
end

#doc_urlObject



21
22
23
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 21

def doc_url
  CGI.unescape(hit.hit[:url]).split("dest=").last
end

#fetch_abstractObject



27
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 27

def fetch_abstract = []

#fetch_datesArray<Relaton::Bib::Date>

Returns:

  • (Array<Relaton::Bib::Date>)


40
41
42
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 40

def fetch_dates
  array(doc_date).map { |on| Relaton::Bib::Date.new(type: "published", at: on) }
end

#fetch_editionObject



25
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 25

def fetch_edition = nil

#fetch_relationsObject



28
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 28

def fetch_relations = []

#fetch_sourceArray<Relaton::Bib::Uri>

Returns:

  • (Array<Relaton::Bib::Uri>)


52
53
54
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 52

def fetch_source
  [Relaton::Bib::Uri.new(type: "src", content: doc_url)]
end

#fetch_statusObject



26
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 26

def fetch_status = nil

#fetch_titlesArray<Relaton::Bib::Title>

Returns:

  • (Array<Relaton::Bib::Title>)


32
33
34
35
36
37
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 32

def fetch_titles
  title = doc.at("//title")&.text&.strip
  return [] if title.nil? || title.empty?

  Relaton::Bib::Title.from_string title, "en", "Latn"
end

#fetch_workgroupObject



29
# File 'lib/relaton/itu/radio_regulations_parser.rb', line 29

def fetch_workgroup = nil