Class: Relaton3gpp::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_3gpp/parser.rb

Constant Summary collapse

DOCTYPES =
{ "TS" => "Technical Specification", "TR" => "Technical Report"}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ Parser

Document parser initalization

Parameters:

  • row (CSV::Row)

    CSV row



10
11
12
# File 'lib/relaton_3gpp/parser.rb', line 10

def initialize(row)
  @row = row
end

Class Method Details

.parse(row) ⇒ RelatonBib:BibliographicItem?

Initialize document parser and run it

Parameters:

  • row (CSV:Row)

    CSV row

Returns:

  • (RelatonBib:BibliographicItem, nil)

    bibliographic item



21
22
23
# File 'lib/relaton_3gpp/parser.rb', line 21

def self.parse(row)
  new(row).parse
end

Instance Method Details

#create_workgroup(name, type) ⇒ Object



176
177
178
179
# File 'lib/relaton_3gpp/parser.rb', line 176

def create_workgroup(name, type)
  wgf = RelatonBib::WorkGroup.new(name: name, type: type)
  RelatonBib::TechnicalCommittee.new(wgf)
end

#doctype_abbrObject



120
121
122
# File 'lib/relaton_3gpp/parser.rb', line 120

def doctype_abbr
  @row["Is TS"] == "1" ? "TS" : "TR"
end

#numberString

Generate number

Returns:

  • (String)

    number



106
107
108
109
110
# File 'lib/relaton_3gpp/parser.rb', line 106

def number
  num = "#{doctype_abbr} #{@row[0]}"
  num += ":#{release}" if release
  "#{num}/#{version}"
end

#parseRelaton3gpp:BibliographicItem?

Parse document

Returns:

  • (Relaton3gpp:BibliographicItem, nil)

    bibliographic item



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/relaton_3gpp/parser.rb', line 30

def parse # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  Relaton3gpp::BibliographicItem.new(
    type: "standard",
    language: ["en"],
    script: ["Latn"],
    title: parse_title,
    link: parse_link,
    # abstract: parse_abstract,
    docid: parse_docid,
    docnumber: number,
    date: parse_date,
    doctype: parse_doctype,
    editorialgroup: parse_editorialgroup,
    version: parse_version,
    # biblionote: parse_note,
    # docstatus: parse_status,
    radiotechnology: parse_radiotechnology,
    # common_ims_spec: @spec[:ComIMS] == "1",
    # internal: @spec[:"For publication"] == "0",
    release: parse_release,
    contributor: parse_contributor,
    place: parse_place,
  )
end

#parse_contributorArray<RelatonBib::ContributionInfo>

Create contributors

Returns:

  • (Array<RelatonBib::ContributionInfo>)

    contributor



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/relaton_3gpp/parser.rb', line 253

def parse_contributor # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  address = RelatonBib::Address.new(
    street: ["c/o ETSI 650, route des Lucioles", "3GPP Mobile Competence Centre"],
    postcode: "06921", city: "Sophia Antipolis Cedex", country: "France"
  )
  org = RelatonBib::Organization.new(
    name: "3rd Generation Partnership Project", abbreviation: "3GPP", contact: [address],
  )
  roles = [{ type: "author" }, { type: "publisher" }]
  contribs = [RelatonBib::ContributionInfo.new(entity: org, role: roles)]
  return contribs unless @row["Last Name"] && @row["Last Name"] != "Vacant"

  aff = []
  if @row["Organisation"]
    org = RelatonBib::Organization.new(name: @row["Organisation"])
    aff << RelatonBib::Affiliation.new(organization: org)
  end
  surname = RelatonBib::LocalizedString.new @row["Last Name"], "en", "Latn"
  forename = RelatonBib::Forename.new content: @row["First Name"], language: ["en"], script: ["Latn"]
  name = RelatonBib::FullName.new(surname: surname, forename: [forename])
  person = RelatonBib::Person.new(name: name, affiliation: aff)
  role = { type: "author" }
  contribs << RelatonBib::ContributionInfo.new(entity: person, role: [role])
end

#parse_dateArray<RelatonBib::BibliographicDate>

Parse date

Returns:

  • (Array<RelatonBib::BibliographicDate>)

    date



146
147
148
149
150
151
152
153
# File 'lib/relaton_3gpp/parser.rb', line 146

def parse_date
  dates = []
  if @row["Date"]
    on = Date.parse(@row["Date"]).to_s
    dates << RelatonBib::BibliographicDate.new(type: "published", on: on)
  end
  dates
end

#parse_docidArra<RelatonBib::DocumentIdentifier>

Parse docidentifier

Returns:

  • (Arra<RelatonBib::DocumentIdentifier>)

    docidentifier



97
98
99
# File 'lib/relaton_3gpp/parser.rb', line 97

def parse_docid
  [RelatonBib::DocumentIdentifier.new(type: "3GPP", id: "3GPP #{number}", primary: true)]
end

#parse_doctypeObject



155
156
157
158
# File 'lib/relaton_3gpp/parser.rb', line 155

def parse_doctype
  # type = DOCTYPES[doctype_abbr]
  DocumentType.new(type: doctype_abbr)
end

#parse_editorialgroupRelatonBib::EditorialGroup

Parse editorialgroup

Returns:

  • (RelatonBib::EditorialGroup)

    editorialgroups



165
166
167
168
169
170
171
172
173
174
# File 'lib/relaton_3gpp/parser.rb', line 165

def parse_editorialgroup # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  eg = []
  prime = @row["Responsible Primary"]
  eg << create_workgroup(prime, "prime") if prime

  @row["Responsible Secondary"].strip.split(", ").each do |wg|
    eg << create_workgroup(wg, "other")
  end
  RelatonBib::EditorialGroup.new eg
end

Parse link

Returns:

  • (Array<RelatonBib::TypedUri>)

    link



75
76
77
78
79
# File 'lib/relaton_3gpp/parser.rb', line 75

def parse_link
  return [] unless @row["Link"]

  [RelatonBib::TypedUri.new(type: "src", content: @row["Link"])]
end

#parse_placeObject



55
56
57
58
# File 'lib/relaton_3gpp/parser.rb', line 55

def parse_place
  country = RelatonBib::Place::RegionType.new name: "France", iso: "FR"
  [RelatonBib::Place.new(city: "Sophia Antipolis Cedex", country: [country])]
end

#parse_radiotechnologyString

Parse radio technology

Returns:

  • (String)

    radio technology



215
216
217
218
219
220
221
222
# File 'lib/relaton_3gpp/parser.rb', line 215

def parse_radiotechnology
  case @row["WPM Code 3G"]
  when /5G/ then "5G"
  when /4G/ then "LTE"
  when /3G/ then "3G"
  else @row["WPM Code 2G"] && "2G"
  end
end

#parse_releaseRelaton3gpp::Release?

Parse release

Returns:



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/relaton_3gpp/parser.rb', line 229

def parse_release # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  project_start = Date.parse(@row["Project Start"]).to_s if @row["Project Start"]
  project_end = Date.parse(@row["Project End"]).to_s if @row["Project End"]
  Release.new(
    # version2g: @rel[:version_2g],
    # version3g: @rel[:version_3g],
    # defunct: @rel[:defunct] == "1",
    wpm_code_2g: @row["WPM Code 2G"],
    wpm_code_3g: @row["WPM Code 3G"],
    # freeze_meeting: @rel[:"freeze meeting"],
    freeze_stage1_meeting: @row["Stage 1 Freeze"],
    freeze_stage2_meeting: @row["Stage 2 Freeze"],
    freeze_stage3_meeting: @row["Stage 3 Freeze"],
    close_meeting: @row["Close Meeting"],
    project_start: project_start,
    project_end: project_end,
  )
end

#parse_titleRelatonBib::TypedTitleStringCollection

Parse title

Returns:

  • (RelatonBib::TypedTitleStringCollection)

    title



65
66
67
68
# File 'lib/relaton_3gpp/parser.rb', line 65

def parse_title
  t = RelatonBib::TypedTitleString.new content: @row["Title"], type: "main"
  RelatonBib::TypedTitleStringCollection.new [t]
end

#parse_versionObject



116
117
118
# File 'lib/relaton_3gpp/parser.rb', line 116

def parse_version
  [RelatonBib::BibliographicItem::Version.new(nil, version)]
end

#releaseObject



124
125
126
127
128
129
130
# File 'lib/relaton_3gpp/parser.rb', line 124

def release
  @release ||=  case @row["WPM Code 2G"]
                when /Release_(\d+)/ then "REL-#{$1}"
                when /PH(\d+)/ then "Ph#{$1}"
                else @row["Release"]
                end
end

#versionObject



112
113
114
# File 'lib/relaton_3gpp/parser.rb', line 112

def version
  @row["Version"]
end