Module: Relaton::Itu::DataParserR

Extended by:
DataParserR
Included in:
DataParserR
Defined in:
lib/relaton/itu/data_parser_r.rb

Constant Summary collapse

TYPE_MAP =
{
  "ITU-R Recommendations" => "recommendation",
  "ITU-R Questions" => "question",
  "ITU-R Reports" => "technical-report",
  "Handbooks" => "handbook",
  "ITU-R Resolutions" => "resolution",
}.freeze

Instance Method Summary collapse

Instance Method Details

#fetch_date(result) ⇒ Array<Relaton::Bib::Date>

Parameters:

  • result (Hash)

Returns:

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


55
56
57
58
59
60
61
62
63
# File 'lib/relaton/itu/data_parser_r.rb', line 55

def fetch_date(result)
  prop = property(result, "Publication date")
  return [] unless prop

  date = parse_pub_date(prop)
  return [] unless date

  [Relaton::Bib::Date.new(type: "published", at: date)]
end

#fetch_docid(result) ⇒ Array<Relaton::Bib::Docidentifier>

Parameters:

  • result (Hash)

Returns:

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


35
36
37
38
39
40
41
42
# File 'lib/relaton/itu/data_parser_r.rb', line 35

def fetch_docid(result)
  title = result["Title"].to_s
  id = title.match(/^(ITU-R\s+\S+)/)&.captures&.first
  return [] unless id

  id = id.sub(/\s*\(.*/, "")
  [Docidentifier.new(type: "ITU", content: id, primary: true)]
end

#fetch_doctype(result) ⇒ Relaton::Itu::Doctype?

Parameters:

  • result (Hash)

Returns:



79
80
81
82
83
84
85
# File 'lib/relaton/itu/data_parser_r.rb', line 79

def fetch_doctype(result)
  type_value = property(result, "Type")
  mapped = TYPE_MAP[type_value]
  return unless mapped

  Doctype.new(content: mapped)
end

#fetch_source(result) ⇒ Array<Relaton::Bib::Uri>

Parameters:

  • result (Hash)

Returns:

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


67
68
69
70
71
72
73
74
75
# File 'lib/relaton/itu/data_parser_r.rb', line 67

def fetch_source(result)
  locations = result["Locations"]
  return [] unless locations.is_a?(Array)

  pdf = locations.find { |l| l["Type"] == "pdf" }
  return [] unless pdf && pdf["RawHref"]

  [Relaton::Bib::Uri.new(type: "pdf", content: pdf["RawHref"])]
end

#fetch_title(result) ⇒ Array<Relaton::Bib::Title>

Parameters:

  • result (Hash)

Returns:

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


46
47
48
49
50
51
# File 'lib/relaton/itu/data_parser_r.rb', line 46

def fetch_title(result)
  title = result["Title"].to_s
  content = title.sub(/^[^:]+:\s*/, "").strip
  content = title unless content.length > 0
  [Relaton::Bib::Title.new(type: "main", content: content, language: "en", script: "Latn")]
end

#parse(result) ⇒ Relaton::Itu::ItemData

Parse ITU-R document from search API result.

Parameters:

  • result (Hash)

    single search result from the API

Returns:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/relaton/itu/data_parser_r.rb', line 21

def parse(result)
  doctype = fetch_doctype(result)
  return unless doctype

  Relaton::Itu::ItemData.new(
    docidentifier: fetch_docid(result), title: fetch_title(result),
    date: fetch_date(result), language: ["en"],
    source: fetch_source(result), script: ["Latn"],
    type: "standard", ext: Relaton::Itu::Ext.new(doctype: doctype, flavor: "itu"),
  )
end