Module: Cosing::Annex
- Defined in:
- lib/cosing/annex.rb,
lib/cosing/annex/v.rb,
lib/cosing/annex/ii.rb,
lib/cosing/annex/iv.rb,
lib/cosing/annex/vi.rb,
lib/cosing/annex/iii.rb,
lib/cosing/annex/base.rb,
lib/cosing/annex/rule.rb,
lib/cosing/annex/sccs_opinion.rb
Defined Under Namespace
Classes: Base, II, III, IV, Rule, SccsOpinion, V, VI
Class Method Summary
collapse
Class Method Details
.build_cas_numbers(row) ⇒ Object
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/cosing/annex.rb', line 68
def build_cas_numbers(row)
Cosing::Parser.transform_array!(
row,
key: :cas_number,
split: "/"
).map do |cas_number|
match = cas_number.match(Patterns::CAS_NUMBER)
match[:cas_number] if match
end
end
|
.build_ec_numbers(row) ⇒ Object
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/cosing/annex.rb', line 79
def build_ec_numbers(row)
Cosing::Parser.transform_array!(
row,
key: :ec_number,
split: "/"
).map do |ec_number|
match = ec_number.match(Patterns::EC_NUMBER)
match[:ec_number] if match
end
end
|
.build_sccs_opinions(row) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/cosing/annex.rb', line 53
def build_sccs_opinions(row)
Cosing::Parser.transform_array!(
row,
key: :sccs_opinions,
split: ";"
).map do |opinion|
code, *description = opinion.split("-")
SccsOpinion.new(
code:,
description: description.join("-")
)
end
end
|
.load ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/cosing/annex.rb', line 41
def load
ii, iii, iv, v, vi = [
Annex::II,
Annex::III,
Annex::IV,
Annex::V,
Annex::VI
].map(&:load)
{ ii:, iii:, iv:, v:, vi: }
end
|
.parse(path) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/cosing/annex.rb', line 16
def parse(path)
CSV.parse(
File.read(Cosing.gem_path(path)),
headers: true,
liberal_parsing: true,
header_converters: :symbol
) do |row|
row = row
.to_h
.transform_values do |value|
value.to_s.strip.then { |val| val == "-" ? "" : val }
end
cas_numbers = build_cas_numbers(row)
ec_numbers = build_ec_numbers(row)
sccs_opinions = build_sccs_opinions(row)
yield row.merge(
cas_numbers: cas_numbers.compact,
ec_numbers: ec_numbers.compact,
sccs_opinions: sccs_opinions.compact
)
end
end
|