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>)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/relaton/itu/data_parser_r.rb', line 60

def fetch_date(result)
  prop = property(result, "Publication date")
  unless prop
    @errors[:date] &&= true
    return []
  end

  date = parse_pub_date(prop)
  unless date
    @errors[:date] &&= true
    return []
  end

  r = [Relaton::Bib::Date.new(type: "published", at: date)]
  @errors[:date] &&= r.empty?
  r
end

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

Parameters:

  • result (Hash)

Returns:

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


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

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

  id = id.sub(/\s*\(.*/, "")
  result_ids = [Docidentifier.new(type: "ITU", content: id, primary: true)]
  @errors[:docid] &&= result_ids.empty?
  result_ids
end

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

Parameters:

  • result (Hash)

Returns:



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/relaton/itu/data_parser_r.rb', line 100

def fetch_doctype(result)
  type_value = property(result, "Type")
  mapped = TYPE_MAP[type_value]
  unless mapped
    @errors[:doctype] &&= true
    return
  end

  @errors[:doctype] &&= false
  Doctype.new(content: mapped)
end

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

Parameters:

  • result (Hash)

Returns:

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


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/relaton/itu/data_parser_r.rb', line 80

def fetch_source(result)
  locations = result["Locations"]
  unless locations.is_a?(Array)
    @errors[:source] &&= true
    return []
  end

  pdf = locations.find { |l| l["Type"] == "pdf" }
  unless pdf && pdf["RawHref"]
    @errors[:source] &&= true
    return []
  end

  r = [Relaton::Bib::Uri.new(type: "pdf", content: pdf["RawHref"])]
  @errors[:source] &&= r.empty?
  r
end

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

Parameters:

  • result (Hash)

Returns:

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


49
50
51
52
53
54
55
56
# File 'lib/relaton/itu/data_parser_r.rb', line 49

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

#parse(result, errors = {}) ⇒ 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
32
# File 'lib/relaton/itu/data_parser_r.rb', line 21

def parse(result, errors = {})
  @errors = errors
  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