Class: Relaton::Etsi::DataParser

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton/etsi/data_parser.rb

Constant Summary collapse

ATTRS =
%i[
  title docnumber source date docidentifier version status contributor
  keyword ext abstract language script
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(row, errors = {}) ⇒ DataParser

Returns a new instance of DataParser.



10
11
12
13
# File 'lib/relaton/etsi/data_parser.rb', line 10

def initialize(row, errors = {})
  @row = row
  @errors = errors
end

Instance Method Details

#abstractObject



189
190
191
192
193
194
195
196
197
# File 'lib/relaton/etsi/data_parser.rb', line 189

def abstract
  result = if @row["Scope"]
             [Bib::Abstract.new(content: @row["Scope"], language: "en", script: "Latn")]
           else
             []
           end
  @errors[:abstract] &&= result.empty?
  result
end

#committee_contributorObject



135
136
137
138
139
140
141
# File 'lib/relaton/etsi/data_parser.rb', line 135

def committee_contributor
  desc = Bib::LocalizedMarkedUpString.new(content: "committee")
  role = Bib::Contributor::Role.new(
    type: "author", description: [desc],
  )
  Bib::Contributor.new(organization: committee_org, role: [role])
end

#committee_orgObject



143
144
145
146
147
148
149
# File 'lib/relaton/etsi/data_parser.rb', line 143

def committee_org
  Bib::Organization.new(
    name: [etsi_name],
    abbreviation: etsi_abbreviation,
    subdivision: [technical_committee_subdivision],
  )
end

#contributorObject



105
106
107
108
109
# File 'lib/relaton/etsi/data_parser.rb', line 105

def contributor
  contribs = [publisher_contributor]
  contribs << committee_contributor if @row["Technical body"]
  contribs
end

#dateObject



61
62
63
64
65
66
67
68
69
# File 'lib/relaton/etsi/data_parser.rb', line 61

def date
  result = if pubid&.date
             [Bib::Date.new(type: "published", at: pubid.date)]
           else
             []
           end
  @errors[:date] &&= result.empty?
  result
end

#docidentifierObject



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/relaton/etsi/data_parser.rb', line 71

def docidentifier
  result = if @row["ETSI deliverable"]
             [Bib::Docidentifier.new(
               content: @row["ETSI deliverable"],
               type: "ETSI",
               primary: true,
             )]
           else
             []
           end
  @errors[:docidentifier] &&= result.empty?
  result
end

#docnumberObject



45
46
47
# File 'lib/relaton/etsi/data_parser.rb', line 45

def docnumber
  @row["ETSI deliverable"]
end

#doctypeObject



183
184
185
186
187
# File 'lib/relaton/etsi/data_parser.rb', line 183

def doctype
  return unless pubid

  Doctype.create_from_abbreviation pubid.type
end

#etsi_abbreviationObject



127
128
129
130
131
132
133
# File 'lib/relaton/etsi/data_parser.rb', line 127

def etsi_abbreviation
  Bib::LocalizedString.new(
    content: "ETSI",
    language: "en",
    script: "Latn",
  )
end

#etsi_nameObject



151
152
153
154
155
# File 'lib/relaton/etsi/data_parser.rb', line 151

def etsi_name
  Bib::TypedLocalizedString.new(
    content: "European Telecommunications Standards Institute",
  )
end

#etsi_org_nameObject



119
120
121
122
123
124
125
# File 'lib/relaton/etsi/data_parser.rb', line 119

def etsi_org_name
  Bib::TypedLocalizedString.new(
    content: "European Telecommunications Standards Institute",
    language: "en",
    script: "Latn",
  )
end

#extObject



179
180
181
# File 'lib/relaton/etsi/data_parser.rb', line 179

def ext
  Ext.new(doctype: doctype, flavor: "etsi")
end

#keywordObject



166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/relaton/etsi/data_parser.rb', line 166

def keyword
  unless @row["Keywords"]
    @errors[:keyword] &&= true
    return []
  end

  result = @row["Keywords"].split(",").map do |kw|
    Bib::Keyword.new(vocab: Bib::LocalizedString.new(content: kw.strip, language: "en", script: "Latn"))
  end
  @errors[:keyword] &&= result.empty?
  result
end

#languageObject



199
200
201
# File 'lib/relaton/etsi/data_parser.rb', line 199

def language
  ["en"]
end

#parseObject



15
16
17
18
# File 'lib/relaton/etsi/data_parser.rb', line 15

def parse
  args = ATTRS.to_h { |attr| [attr, send(attr)] }
  ItemData.new(type: "standard", **args)
end

#pubidObject



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

def pubid
  return @pubid if defined?(@pubid)

  unless @row["ETSI deliverable"]
    @errors[:pubid] &&= true
    @pubid = nil
    return @pubid
  end

  @errors[:pubid] &&= false
  @pubid = PubId.parse(@row["ETSI deliverable"])
end

#publisher_contributorObject



111
112
113
114
115
116
117
# File 'lib/relaton/etsi/data_parser.rb', line 111

def publisher_contributor
  org = Bib::Organization.new(
    name: [etsi_org_name], abbreviation: etsi_abbreviation,
  )
  role = Bib::Contributor::Role.new(type: "publisher")
  Bib::Contributor.new(organization: org, role: [role])
end

#scriptObject



203
204
205
# File 'lib/relaton/etsi/data_parser.rb', line 203

def script
  ["Latn"]
end

#sourceObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/relaton/etsi/data_parser.rb', line 49

def source
  urls = []
  if @row["Details link"]
    urls << Bib::Uri.new(content: @row["Details link"], type: "src")
  end
  if @row["PDF link"]
    urls << Bib::Uri.new(content: @row["PDF link"], type: "pdf")
  end
  @errors[:source] &&= urls.empty?
  urls
end

#statusObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/relaton/etsi/data_parser.rb', line 91

def status
  unless @row["Status"]
    @errors[:status] &&= true
    return
  end

  stage = @row["Status"]
  if stage == "On Approval"
    stage = "#{pubid&.type} approval"
  end
  @errors[:status] &&= false
  Status.new(stage: stage)
end

#technical_committee_subdivisionObject



157
158
159
160
161
162
163
164
# File 'lib/relaton/etsi/data_parser.rb', line 157

def technical_committee_subdivision
  Bib::Subdivision.new(
    name: [Bib::TypedLocalizedString.new(
      content: @row["Technical body"],
    )],
    type: "technical-committee",
  )
end

#titleObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/relaton/etsi/data_parser.rb', line 33

def title
  result = if @row["title"]
             [Bib::Title.new(
               content: @row["title"], language: "en", script: "Latn",
             )]
           else
             []
           end
  @errors[:title] &&= result.empty?
  result
end

#versionObject



85
86
87
88
89
# File 'lib/relaton/etsi/data_parser.rb', line 85

def version
  return [] unless pubid&.version

  [Bib::Version.new(draft: pubid.version)]
end