iev 0.4.5 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +56 -21
- data/CLAUDE.md +27 -5
- data/Gemfile +9 -0
- data/README.adoc +10 -3
- data/iev.gemspec +3 -2
- data/lib/iev/bibliography_builder.rb +87 -0
- data/lib/iev/cli/command.rb +3 -2
- data/lib/iev/cli/ui.rb +5 -5
- data/lib/iev/config.rb +1 -15
- data/lib/iev/data_source.rb +4 -2
- data/lib/iev/db_writer.rb +1 -0
- data/lib/iev/exporter.rb +139 -21
- data/lib/iev/figure_builder.rb +186 -0
- data/lib/iev/iso_639_code.rb +2 -1
- data/lib/iev/relaton_db.rb +1 -1
- data/lib/iev/scraper/browser.rb +90 -88
- data/lib/iev/scraper.rb +5 -4
- data/lib/iev/source_parser.rb +9 -10
- data/lib/iev/subject_area_concepts.rb +36 -33
- data/lib/iev/subject_areas.rb +9 -11
- data/lib/iev/term_attrs_parser.rb +1 -1
- data/lib/iev/term_builder.rb +14 -9
- data/lib/iev/utilities.rb +29 -1
- data/lib/iev/version.rb +1 -1
- data/lib/iev.rb +30 -6
- metadata +24 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a965bb1653227f1b4ba8ebc27e9f3a67950d359cec2f809b46d4e0edebec18e9
|
|
4
|
+
data.tar.gz: 5414e80f45caf460970d75052dc7bd7ec931d697f267de0ea2df6abd6a2209ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 805143019d38cf0ed15e6526b8b727e681e8e3361b25d3c58ea71f6b2b4cf66eb3dda9882bcb8f038317bc4f1bd84554f6abdd14e4575774c2572a08b45c8865
|
|
7
|
+
data.tar.gz: 204a790f8cc565859a3abb9f64b137b235a559bbb411f52fee15989b467c5860ff2fe3073c65495f5c28e1e01a251375c533139cac07eaefb7341b5016669d1a
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
|
@@ -1,65 +1,100 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
2
|
# `rubocop --auto-gen-config`
|
|
3
|
-
# on
|
|
3
|
+
# on 2026-06-18 12:23:48 UTC using RuboCop version 1.86.1.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
|
8
8
|
|
|
9
|
-
# Offense count:
|
|
9
|
+
# Offense count: 1
|
|
10
|
+
Gemspec/RequiredRubyVersion:
|
|
11
|
+
Exclude:
|
|
12
|
+
- 'iev.gemspec'
|
|
13
|
+
|
|
14
|
+
# Offense count: 64
|
|
10
15
|
# This cop supports safe autocorrection (--autocorrect).
|
|
11
|
-
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes,
|
|
16
|
+
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
|
|
12
17
|
# URISchemes: http, https
|
|
13
18
|
Layout/LineLength:
|
|
14
|
-
|
|
15
|
-
- 'iev.gemspec'
|
|
16
|
-
- 'lib/iev/cli/command.rb'
|
|
17
|
-
- 'lib/iev/cli/command_helper.rb'
|
|
18
|
-
- 'lib/iev/db_cache.rb'
|
|
19
|
-
- 'lib/iev/source_parser.rb'
|
|
20
|
-
- 'spec/acceptance/db2yaml_spec.rb'
|
|
21
|
-
- 'spec/acceptance/xlsx2yaml_spec.rb'
|
|
22
|
-
- 'spec/iev_spec.rb'
|
|
19
|
+
Enabled: false
|
|
23
20
|
|
|
24
|
-
# Offense count:
|
|
21
|
+
# Offense count: 19
|
|
25
22
|
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
|
|
26
23
|
Lint/DuplicateBranch:
|
|
27
24
|
Exclude:
|
|
28
25
|
- 'lib/iev/source_parser.rb'
|
|
29
|
-
- 'lib/iev/
|
|
26
|
+
- 'lib/iev/utilities.rb'
|
|
30
27
|
|
|
31
28
|
# Offense count: 1
|
|
32
29
|
Lint/MixedRegexpCaptureTypes:
|
|
33
30
|
Exclude:
|
|
34
31
|
- 'lib/iev/term_builder.rb'
|
|
35
32
|
|
|
36
|
-
# Offense count:
|
|
33
|
+
# Offense count: 2
|
|
34
|
+
Lint/ShadowedException:
|
|
35
|
+
Exclude:
|
|
36
|
+
- 'lib/iev/source_parser.rb'
|
|
37
|
+
|
|
38
|
+
# Offense count: 27
|
|
37
39
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
|
38
40
|
Metrics/AbcSize:
|
|
39
41
|
Exclude:
|
|
42
|
+
- 'lib/iev/cli/command.rb'
|
|
43
|
+
- 'lib/iev/cli/command_helper.rb'
|
|
40
44
|
- 'lib/iev/converter/mathml_to_asciimath.rb'
|
|
41
45
|
- 'lib/iev/db_writer.rb'
|
|
46
|
+
- 'lib/iev/exporter.rb'
|
|
47
|
+
- 'lib/iev/scraper/page_parser.rb'
|
|
42
48
|
- 'lib/iev/source_parser.rb'
|
|
49
|
+
- 'lib/iev/subject_area_concepts.rb'
|
|
50
|
+
- 'lib/iev/subject_areas.rb'
|
|
43
51
|
- 'lib/iev/term_builder.rb'
|
|
52
|
+
- 'lib/iev/utilities.rb'
|
|
53
|
+
- 'spec/iev/supersession_parser_spec.rb'
|
|
44
54
|
|
|
45
|
-
# Offense count:
|
|
55
|
+
# Offense count: 15
|
|
46
56
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
|
47
57
|
Metrics/CyclomaticComplexity:
|
|
48
58
|
Exclude:
|
|
49
|
-
- 'lib/iev.rb'
|
|
50
59
|
- 'lib/iev/converter/mathml_to_asciimath.rb'
|
|
60
|
+
- 'lib/iev/exporter.rb'
|
|
61
|
+
- 'lib/iev/scraper/page_parser.rb'
|
|
51
62
|
- 'lib/iev/source_parser.rb'
|
|
63
|
+
- 'lib/iev/subject_areas.rb'
|
|
52
64
|
- 'lib/iev/term_builder.rb'
|
|
65
|
+
- 'lib/iev/utilities.rb'
|
|
53
66
|
|
|
54
|
-
# Offense count:
|
|
67
|
+
# Offense count: 36
|
|
55
68
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
|
56
69
|
Metrics/MethodLength:
|
|
57
|
-
Max:
|
|
70
|
+
Max: 73
|
|
71
|
+
|
|
72
|
+
# Offense count: 1
|
|
73
|
+
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
|
74
|
+
Metrics/ParameterLists:
|
|
75
|
+
Max: 7
|
|
58
76
|
|
|
59
|
-
# Offense count:
|
|
77
|
+
# Offense count: 8
|
|
60
78
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
|
61
79
|
Metrics/PerceivedComplexity:
|
|
62
80
|
Exclude:
|
|
63
|
-
- 'lib/iev.rb'
|
|
64
81
|
- 'lib/iev/converter/mathml_to_asciimath.rb'
|
|
82
|
+
- 'lib/iev/exporter.rb'
|
|
83
|
+
- 'lib/iev/scraper/page_parser.rb'
|
|
84
|
+
- 'lib/iev/subject_areas.rb'
|
|
65
85
|
- 'lib/iev/term_builder.rb'
|
|
86
|
+
|
|
87
|
+
# Offense count: 1
|
|
88
|
+
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
|
89
|
+
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
|
|
90
|
+
Naming/MethodParameterName:
|
|
91
|
+
Exclude:
|
|
92
|
+
- 'lib/iev/subject_areas.rb'
|
|
93
|
+
|
|
94
|
+
# Offense count: 2
|
|
95
|
+
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
|
|
96
|
+
# SupportedStyles: snake_case, normalcase, non_integer
|
|
97
|
+
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
|
|
98
|
+
Naming/VariableNumber:
|
|
99
|
+
Exclude:
|
|
100
|
+
- 'spec/iev/exporter_spec.rb'
|
data/CLAUDE.md
CHANGED
|
@@ -27,15 +27,33 @@ This is a Ruby gem (`iev`) for working with the International Electrotechnical V
|
|
|
27
27
|
|
|
28
28
|
### Key Modules
|
|
29
29
|
|
|
30
|
-
- `TermBuilder` — the core converter that turns a spreadsheet row into a `Glossarist::LocalizedConcept`. Handles definition splitting (notes/examples extraction), term designation parsing, and source parsing.
|
|
30
|
+
- `TermBuilder` — the core converter that turns a spreadsheet row into a `Glossarist::LocalizedConcept`. Handles definition splitting (notes/examples extraction), term designation parsing, and source parsing. Sets `ConceptData#domain` to section/area title text (not URI).
|
|
31
31
|
- `SourceParser` — parses the SOURCE column from IEV exports, normalizing references (CEI→IEC, UIT→ITU, etc.) and extracting ref/clause/relationship using extensive regex matching.
|
|
32
|
-
- `TermAttrsParser` — parses the TERMATTRIBUTE field (gender, plurality, part of speech, geographical area,
|
|
32
|
+
- `TermAttrsParser` — parses the TERMATTRIBUTE field (gender, plurality, part of speech, geographical area, usage_info).
|
|
33
33
|
- `SupersessionParser` — parses the REPLACES field for deprecated term relationships.
|
|
34
34
|
- `SubjectAreas` — manages the IEV subject area/section hierarchy. Bundled `data/subject_areas.yaml` contains the area/section tree. URI scheme: `area-{code}` and `section-{code}`.
|
|
35
|
-
- `SubjectAreaConcepts` — builds area and section hierarchy concepts
|
|
36
|
-
- `Exporter` — full export pipeline (Excel/SQLite → Glossarist YAML). Assigns domain `ConceptReference` objects via `domain_references_for`.
|
|
35
|
+
- `SubjectAreaConcepts` — builds area and section hierarchy concepts. Uses `ConceptReference` with proper `ref_type` per `ConceptReferenceType`: `"domain"` for thematic area classification, `"section"` for structural section membership. Sets `ConceptData#domain` to area title text.
|
|
36
|
+
- `Exporter` — full export pipeline (Excel/SQLite → Glossarist YAML). Assigns domain and section `ConceptReference` objects via `domain_references_for`. Uses `Glossarist::DatasetRegister` model for `register.yaml`. Sets `schema_version: "3"` on all exported concepts. Pipeline order: build → subject areas → section relations → figure extraction → reference enrichment → save concepts → save figures → save bibliography → save register.
|
|
37
|
+
- `FigureBuilder` — destructive extraction pass that hoists AsciiDoc image macros (emitted from SIMG tags by `Utilities`) into dataset-shared `Glossarist::Figure` entities. Rewrites inline text to `{{fig:id, display}}` mentions and adds `FigureReference` entries to `ManagedConceptData#figures`. One Figure entity per unique image file; captions merge across languages.
|
|
38
|
+
- `BibliographyBuilder` — collects unique `(source, id)` pairs from every concept's sources (localized and managed) into a `Glossarist::BibliographyData`. Entry ids are normalized with the same rules as `Glossarist::Validation::BibliographyIndex` so consumers can resolve anchors.
|
|
37
39
|
- `Converter::MathmlToAsciimath` — converts MathML markup to AsciiMath using Plurimath.
|
|
38
|
-
- `Utilities` — HTML processing: converts IEV cross-references (`<a href=IEV...>`) to `{{
|
|
40
|
+
- `Utilities` — HTML processing: converts IEV cross-references (`<a href=IEV...>`) to `{{URN, term}}` format (ID first, display text last), handles figures, images, bold tags, and newline normalization.
|
|
41
|
+
|
|
42
|
+
### Domain/Section Model
|
|
43
|
+
|
|
44
|
+
Per the concept model's `ConceptReferenceType`:
|
|
45
|
+
- `"domain"` — thematic/subject-area classification (area level, e.g. "103")
|
|
46
|
+
- `"section"` — structural section membership (section level, e.g. "103-01")
|
|
47
|
+
|
|
48
|
+
Each concept's `ManagedConceptData#domains` contains both refs. `ConceptData#domain` (a `LocalizedString`) holds the section/area title text. The `ManagedConcept#related` array holds `broader`/`narrower` relationships for the hierarchy tree.
|
|
49
|
+
|
|
50
|
+
### V3 Output Artifacts
|
|
51
|
+
|
|
52
|
+
An export produces these files alongside the concepts/ directory:
|
|
53
|
+
- `register.yaml` — `Glossarist::DatasetRegister` with section tree, languages, owner, URN.
|
|
54
|
+
- `bibliography.yaml` — single `bibliography:` key wrapping an array of `BibliographyEntry` objects. Entry `id` is the normalized anchor that `Glossarist::Validation::BibliographyIndex` will resolve against.
|
|
55
|
+
- `figures/{fig-id}.yaml` — one `Glossarist::Figure` per unique image. Each concept carries a `FigureReference` on `ManagedConceptData#figures` and an inline `{{fig:id, display}}` mention in the text where the figure appeared.
|
|
56
|
+
- References on localized concepts are populated by `Glossarist::ConceptEnricher#inject_references`, which scans text for `{{urn:...}}`, `<<xref>>`, and `image::` patterns.
|
|
39
57
|
|
|
40
58
|
### Configuration
|
|
41
59
|
|
|
@@ -47,7 +65,11 @@ This is a Ruby gem (`iev`) for working with the International Electrotechnical V
|
|
|
47
65
|
## Key Conventions
|
|
48
66
|
|
|
49
67
|
- Ruby >= 3.1.0 required
|
|
68
|
+
- All constants live under `Iev::` namespace (e.g. `Iev::IEV_SOURCE`, not top-level `IEV_SOURCE`)
|
|
69
|
+
- `Iev.config` / `Iev.configure` / `Iev.reset_config!` are defined directly in `lib/iev.rb` — they must be available at load time without triggering autoload
|
|
50
70
|
- `plurimath` and `unitsml` are optional runtime dependencies — loaded with `rescue LoadError`, so the `DataSource`/`Db` APIs work without them
|
|
51
71
|
- The IEV Excel export format is specific to IEC-internal use; column structure is documented in README.adoc
|
|
52
72
|
- Language codes: the spreadsheet uses ISO 639-1 (2-char like "en"), internally converted to ISO 639-2/3 (3-char like "eng") via `Iso639Code` and `DataConversions`
|
|
53
73
|
- `DataConversions` is a refinement (`using DataConversions`) that adds `.sanitize` and `.decode_html` methods to String
|
|
74
|
+
- `IevCode` is the single source of truth for IEV code decomposition — always use it instead of manual `split("-")` parsing
|
|
75
|
+
- Schema version 3: all exported concepts use `schema_version: "3"`, which supports `annotations`, V3 concept sources, and structured references
|
data/Gemfile
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
+
# Use local glossarist-ruby when available for development.
|
|
6
|
+
# Otherwise falls back to released gem (requires >= 2.8.15 for
|
|
7
|
+
# BibliographyData, Figure/NonVerbRep, and ConceptEnricher support).
|
|
8
|
+
if File.directory?(File.expand_path("../glossarist-ruby", __dir__))
|
|
9
|
+
gem "glossarist", path: "../glossarist-ruby"
|
|
10
|
+
else
|
|
11
|
+
gem "glossarist", ">= 2.8.15"
|
|
12
|
+
end
|
|
13
|
+
|
|
5
14
|
gem "benchmark"
|
|
6
15
|
gem "canon"
|
|
7
16
|
gem "openssl"
|
data/README.adoc
CHANGED
|
@@ -228,7 +228,7 @@ There are these data types inside the term attribute field. Make sure you split
|
|
|
228
228
|
We need to parse out all NOTEs and EXAMPLEs and normalize them.
|
|
229
229
|
|
|
230
230
|
For all `This links to <a href=IEV112-01-01>quantity</a>`, we parse them and replace with:
|
|
231
|
-
`This links to {{
|
|
231
|
+
`This links to {{IEV:112-01-01, quantity}}`.
|
|
232
232
|
|
|
233
233
|
e.g.
|
|
234
234
|
|
|
@@ -300,9 +300,9 @@ notes:
|
|
|
300
300
|
|
|
301
301
|
[source,yaml]
|
|
302
302
|
----
|
|
303
|
-
definition: {{
|
|
303
|
+
definition: {{IEV:112-01-01, quantity}} which keeps the same value under particular circumstances, or which results from theoretical considerations
|
|
304
304
|
examples:
|
|
305
|
-
- {{
|
|
305
|
+
- {{IEV:103-05-26, time constant}}, equilibrium constant for a chemical reaction, {{IEV:112-03-09, fundamental physical constant}}.
|
|
306
306
|
----
|
|
307
307
|
|
|
308
308
|
|
|
@@ -582,6 +582,10 @@ of columns during export:
|
|
|
582
582
|
| Derived from `IEVREF`
|
|
583
583
|
| The IEVREF pattern `AAA-BB-CC` is split. Creates two `ConceptReference` objects with `ref_type: "domain"` and `source: "urn:iec:std:iec:60050"` (IEC URN per IEC URN specification): `area-AAA` and `section-AAA-BB`. For example, `103-01-02` produces `area-103` + `section-103-01`.
|
|
584
584
|
|
|
585
|
+
| `ManagedConceptData#tags`
|
|
586
|
+
| Derived from `IEVREF`
|
|
587
|
+
| Plain string tags for grouping and filtering. Derived from the IEV subject area hierarchy: includes the area title (e.g. `"Mathematics - Functions"`) and section title (e.g. `"General concepts"`).
|
|
588
|
+
|
|
585
589
|
| `LocalizedConcept#classification`
|
|
586
590
|
| `SYNONYM1STATUS`
|
|
587
591
|
| Maps localized classification values: Chinese/Russian/Spanish `"admitido"` to `"admitted"`, various forms of `"preferred"` similarly; other values lowercased as-is.
|
|
@@ -749,6 +753,9 @@ data:
|
|
|
749
753
|
- concept_id: section-103-01
|
|
750
754
|
source: urn:iec:std:iec:60050
|
|
751
755
|
ref_type: domain
|
|
756
|
+
tags:
|
|
757
|
+
- "Mathematics - Functions"
|
|
758
|
+
- "General concepts"
|
|
752
759
|
----
|
|
753
760
|
|
|
754
761
|
The `ref_type: domain` distinguishes domain references from other
|
data/iev.gemspec
CHANGED
|
@@ -22,14 +22,15 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.required_ruby_version = Gem::Requirement.new(">= 3.2.0")
|
|
23
23
|
|
|
24
24
|
spec.add_dependency "creek", "~> 2.6"
|
|
25
|
-
spec.add_dependency "glossarist", "~> 2.6", ">= 2.6.7"
|
|
26
25
|
spec.add_dependency "ferrum", "~> 0.15"
|
|
26
|
+
spec.add_dependency "glossarist", ">= 2.8.15"
|
|
27
|
+
spec.add_dependency "lutaml-model", "~> 0.8.0"
|
|
27
28
|
spec.add_dependency "nokogiri", "~> 1.19"
|
|
28
29
|
spec.add_dependency "plurimath"
|
|
29
|
-
spec.add_dependency "lutaml-model", "~> 0.8.0"
|
|
30
30
|
spec.add_dependency "relaton", ">= 2.0.0", "< 3"
|
|
31
31
|
spec.add_dependency "sequel", "~> 5.40"
|
|
32
32
|
spec.add_dependency "sqlite3", "~> 1.7"
|
|
33
33
|
spec.add_dependency "thor", "~> 1.0"
|
|
34
34
|
spec.add_dependency "unitsml"
|
|
35
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
35
36
|
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Iev
|
|
4
|
+
# Builds a `Glossarist::BibliographyData` from the sources cited across a
|
|
5
|
+
# concept collection.
|
|
6
|
+
#
|
|
7
|
+
# Each unique `(source, id)` pair from a concept's `ConceptSource#origin`
|
|
8
|
+
# becomes one `BibliographyEntry`. The entry's `id` is the normalized
|
|
9
|
+
# anchor that `Glossarist::Validation::BibliographyIndex` uses for
|
|
10
|
+
# resolution — so the same normalization rules are applied here.
|
|
11
|
+
module BibliographyBuilder
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
# @param concepts [Enumerable<Glossarist::ManagedConcept>]
|
|
15
|
+
# @return [Glossarist::BibliographyData]
|
|
16
|
+
def build(concepts)
|
|
17
|
+
entries = collect_entries(concepts)
|
|
18
|
+
Glossarist::BibliographyData.new(entries: entries)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def collect_entries(concepts)
|
|
22
|
+
seen = {}
|
|
23
|
+
concepts.each do |concept|
|
|
24
|
+
concept.localizations.each do |l10n|
|
|
25
|
+
collect_from_l10n(l10n, seen)
|
|
26
|
+
end
|
|
27
|
+
Array(concept.sources).each { |src| add_source_entry(src, seen) }
|
|
28
|
+
end
|
|
29
|
+
seen.values.sort_by(&:id)
|
|
30
|
+
end
|
|
31
|
+
private_class_method :collect_entries
|
|
32
|
+
|
|
33
|
+
def collect_from_l10n(l10n, seen)
|
|
34
|
+
Array(l10n.all_sources).each { |src| add_source_entry(src, seen) }
|
|
35
|
+
end
|
|
36
|
+
private_class_method :collect_from_l10n
|
|
37
|
+
|
|
38
|
+
def add_source_entry(source, seen)
|
|
39
|
+
ref = source_origin_ref(source)
|
|
40
|
+
return unless ref
|
|
41
|
+
|
|
42
|
+
seen[entry_label(ref)] ||= build_entry(ref, source&.origin)
|
|
43
|
+
end
|
|
44
|
+
private_class_method :add_source_entry
|
|
45
|
+
|
|
46
|
+
def source_origin_ref(source)
|
|
47
|
+
ref = source&.origin&.ref
|
|
48
|
+
return unless ref&.source && !ref.source.strip.empty?
|
|
49
|
+
|
|
50
|
+
ref
|
|
51
|
+
end
|
|
52
|
+
private_class_method :source_origin_ref
|
|
53
|
+
|
|
54
|
+
def build_entry(ref, origin)
|
|
55
|
+
label = entry_label(ref)
|
|
56
|
+
Glossarist::BibliographyEntry.new(
|
|
57
|
+
id: normalize_anchor(label),
|
|
58
|
+
reference: label,
|
|
59
|
+
link: origin&.link,
|
|
60
|
+
type: type_for(ref.source),
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
private_class_method :build_entry
|
|
64
|
+
|
|
65
|
+
def entry_label(ref)
|
|
66
|
+
[ref.source, ref.id].compact.join(" ").strip
|
|
67
|
+
end
|
|
68
|
+
private_class_method :entry_label
|
|
69
|
+
|
|
70
|
+
# Mirrors `Glossarist::Validation::BibliographyIndex#normalize_anchor`
|
|
71
|
+
# so the id we write matches what the validator will look up.
|
|
72
|
+
def normalize_anchor(anchor)
|
|
73
|
+
anchor.to_s.gsub(/[ \/:]/, "_").gsub(/__+/, "_").downcase
|
|
74
|
+
end
|
|
75
|
+
private_class_method :normalize_anchor
|
|
76
|
+
|
|
77
|
+
def type_for(source)
|
|
78
|
+
case source.to_s
|
|
79
|
+
when /\A(IEV|VIM|JCGM)/ then "vocabulary"
|
|
80
|
+
when /\AITU/ then "recommendation"
|
|
81
|
+
when /\A(BIPM|BBIPM)/ then "brochure"
|
|
82
|
+
else "standard"
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
private_class_method :type_for
|
|
86
|
+
end
|
|
87
|
+
end
|
data/lib/iev/cli/command.rb
CHANGED
|
@@ -142,14 +142,15 @@ module Iev
|
|
|
142
142
|
summary
|
|
143
143
|
end
|
|
144
144
|
|
|
145
|
-
desc "subject_areas",
|
|
145
|
+
desc "subject_areas",
|
|
146
|
+
"Fetch IEV subject areas and sections from Electropedia."
|
|
146
147
|
option :output, desc: "Output YAML file (default: stdout)", aliases: :o
|
|
147
148
|
option :refresh, type: :boolean, default: false,
|
|
148
149
|
desc: "Force re-fetch even if cached"
|
|
149
150
|
def subject_areas
|
|
150
151
|
if options[:refresh]
|
|
151
152
|
cache_path = File.join(Iev.config.cache_dir, "subject_areas.yaml")
|
|
152
|
-
FileUtils.rm_f(cache_path)
|
|
153
|
+
FileUtils.rm_f(cache_path)
|
|
153
154
|
end
|
|
154
155
|
|
|
155
156
|
result = Iev::SubjectAreas.fetch
|
data/lib/iev/cli/ui.rb
CHANGED
|
@@ -12,12 +12,12 @@ module Iev
|
|
|
12
12
|
module Ui
|
|
13
13
|
module_function
|
|
14
14
|
|
|
15
|
-
def debug(*
|
|
16
|
-
Helper.cli_out(:debug, *
|
|
15
|
+
def debug(*)
|
|
16
|
+
Helper.cli_out(:debug, *)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def warn(*
|
|
20
|
-
Helper.cli_out(:warn, *
|
|
19
|
+
def warn(*)
|
|
20
|
+
Helper.cli_out(:warn, *)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
# Prints progress message which will be replaced on next call.
|
|
@@ -52,7 +52,7 @@ module Iev
|
|
|
52
52
|
|
|
53
53
|
def cli_out(level, *args)
|
|
54
54
|
topic = args[0].is_a?(Symbol) ? args.shift : nil
|
|
55
|
-
message = args.
|
|
55
|
+
message = args.join(" ").chomp
|
|
56
56
|
ui_tag = Thread.current[:iev_ui_tag]
|
|
57
57
|
|
|
58
58
|
return unless should_out?(level, topic)
|
data/lib/iev/config.rb
CHANGED
|
@@ -9,23 +9,9 @@ module Iev
|
|
|
9
9
|
attr_accessor :data_path, :cache_dir, :remote_base_url
|
|
10
10
|
|
|
11
11
|
def initialize
|
|
12
|
-
@data_path = ENV
|
|
12
|
+
@data_path = ENV.fetch("IEV_DATA_PATH", nil)
|
|
13
13
|
@cache_dir = ENV["IEV_CACHE_DIR"] || File.join(Dir.tmpdir, "iev-cache")
|
|
14
14
|
@remote_base_url = DEFAULT_REMOTE_BASE_URL
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
|
-
|
|
18
|
-
class << self
|
|
19
|
-
def config
|
|
20
|
-
@config ||= Config.new
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def configure
|
|
24
|
-
yield(config) if block_given?
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def reset_config!
|
|
28
|
-
@config = nil
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
17
|
end
|
data/lib/iev/data_source.rb
CHANGED
|
@@ -63,7 +63,8 @@ module Iev
|
|
|
63
63
|
path = File.join(data_path, "concept-#{code}.yaml")
|
|
64
64
|
return nil unless File.exist?(path)
|
|
65
65
|
|
|
66
|
-
YAML.safe_load(File.read(path, encoding: "utf-8"),
|
|
66
|
+
YAML.safe_load(File.read(path, encoding: "utf-8"),
|
|
67
|
+
permitted_classes: [Date, Time])
|
|
67
68
|
end
|
|
68
69
|
|
|
69
70
|
def from_remote(code)
|
|
@@ -101,7 +102,8 @@ module Iev
|
|
|
101
102
|
cache_path = cache_file_path(filename)
|
|
102
103
|
return nil unless File.exist?(cache_path)
|
|
103
104
|
|
|
104
|
-
YAML.safe_load(File.read(cache_path, encoding: "utf-8"),
|
|
105
|
+
YAML.safe_load(File.read(cache_path, encoding: "utf-8"),
|
|
106
|
+
permitted_classes: [Date, Time])
|
|
105
107
|
end
|
|
106
108
|
|
|
107
109
|
def write_cache(filename, data)
|