relaton-iec 1.19.1 → 1.20.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7153721bcd73a90080e9ac70e5cc041cb3f943711f11cdd82ef335f01f07cf64
4
- data.tar.gz: 9c84261060e5363ac7f5e961ca38c467703bd3043bd782e764054f407388cf83
3
+ metadata.gz: 075af8973d061da09f15b28a62c0fce39013f6c6e662c2fa1e3ac4566e31633b
4
+ data.tar.gz: d0c18b4633244d88b20ea2fa69bedbbaff2e74421736728cd5c6ed0e821228d5
5
5
  SHA512:
6
- metadata.gz: 10d2990ec6d73858fe68c0f85424c8bf0037205837a3ae3787dc0952de5883f3f104ef56bcf9cd266fed8816e35b5d32c5e0993ff2f2c7eebcb4792e755ab161
7
- data.tar.gz: 900bffdce5c4b87976a351f10d0a75ea17c7efff1bdd8791a0660df5a352e3c6a4701b273882556b6822edc0f3af7dd0fbf439d5dfccc3ee3b491c904a5d65db
6
+ metadata.gz: ae4e37b4b94b7d8f0708189183e54d4488d3144dcab2d000f7372ce9cd1c18d6150196604024c95cb201b24ec4bd26505c0b9278326ce4351d9206480a2bb06a
7
+ data.tar.gz: c2d717a267b3faf09d378fd0b6461107458fabb33ea2e55dba7715859f3aeeca4a5edce7538194468cc5e521c73cd9bfe0676279f9984d616edd59b65efd808f
data/CLAUDE.md ADDED
@@ -0,0 +1,49 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Build and Test Commands
6
+
7
+ ```bash
8
+ bundle install # Install dependencies
9
+ rake spec # Run all tests (or just `rspec`)
10
+ rspec spec/relaton_iec_spec.rb # Run single test file
11
+ rspec spec/relaton_iec_spec.rb:69 # Run test at specific line
12
+ bin/console # Interactive Ruby console with gem loaded
13
+ ```
14
+
15
+ ## Architecture Overview
16
+
17
+ relaton-iec is a Ruby gem that retrieves IEC (International Electrotechnical Commission) standards metadata. It's part of the Relaton family of bibliographic gems.
18
+
19
+ ### Data Flow
20
+
21
+ 1. **Search/Get requests** go through `IecBibliography.get(code, year, opts)` or `.search(ref, year)`
22
+ 2. `HitCollection` queries an index file from GitHub (relaton/relaton-data-iec)
23
+ 3. Individual `Hit` objects fetch full YAML documents from the same GitHub repository
24
+ 4. Results are parsed into `IecBibliographicItem` objects
25
+
26
+ ### Key Classes
27
+
28
+ - **IecBibliography** ([lib/relaton_iec/iec_bibliography.rb](lib/relaton_iec/iec_bibliography.rb)) - Main entry point for searching and fetching standards
29
+ - **IecBibliographicItem** ([lib/relaton_iec/iec_bibliographic_item.rb](lib/relaton_iec/iec_bibliographic_item.rb)) - Extends `RelatonIsoBib::IsoBibliographicItem` with IEC-specific attributes (function, updates_document_type, accessibility_color_inside, cen_processing, secretary, interest_to_committees)
30
+ - **HitCollection** ([lib/relaton_iec/hit_collection.rb](lib/relaton_iec/hit_collection.rb)) - Manages search results from the index
31
+ - **Hit** ([lib/relaton_iec/hit.rb](lib/relaton_iec/hit.rb)) - Single search result; fetches full document on demand from GitHub
32
+ - **DataFetcher** ([lib/relaton_iec/data_fetcher.rb](lib/relaton_iec/data_fetcher.rb)) - Fetches documents from IEC Harmonized API (requires credentials)
33
+ - **Processor** ([lib/relaton_iec/processor.rb](lib/relaton_iec/processor.rb)) - Relaton framework integration
34
+
35
+ ### URN Conversion
36
+
37
+ The module provides `RelatonIec.code_to_urn(code, lang)` and `RelatonIec.urn_to_code(urn)` for converting between document identifiers and URN format.
38
+
39
+ ### Testing
40
+
41
+ - Uses RSpec with VCR for HTTP interaction recording
42
+ - VCR cassettes stored in `spec/vcr_cassettes/`
43
+ - Tests use webmock for HTTP stubbing
44
+
45
+ ### DataFetcher Environment Variables
46
+
47
+ When fetching from IEC Harmonized API directly:
48
+ - `IEC_HAPI_PROJ_PUBS_KEY` - API key
49
+ - `IEC_HAPI_PROJ_PUBS_SECRET` - API secret
@@ -64,13 +64,11 @@ module RelatonIec
64
64
  # @return [RelatonIsoBib::StructuredIdentifier] structured identifier
65
65
  #
66
66
  def structuredidentifier
67
- m = @pub["reference"].match(
68
- /(?<=\s)(?<project>\w+)(?:-(?<part>\w*)(?:-(?<subpart>\w*))?)?/,
69
- )
70
- RelatonIsoBib::StructuredIdentifier.new(
71
- project_number: m[:project], part: m[:part], subpart: m[:subpart],
72
- type: "IEC", id: @pub["reference"]
73
- )
67
+ urn = @pub.dig("project", "urn")
68
+ return unless urn
69
+
70
+ pnum = urn.split(":").last
71
+ RelatonIsoBib::StructuredIdentifier.new(project_number: pnum, type: "IEC")
74
72
  end
75
73
 
76
74
  #
@@ -3,6 +3,20 @@ module RelatonIec
3
3
  include RelatonIsoBib::HashConverter
4
4
  extend self
5
5
 
6
+ def hash_to_bib(hash)
7
+ ret = super
8
+ ret[:function] = ret[:ext][:function] if ret.dig(:ext, :function)
9
+ ret[:updates_document_type] = ret[:ext][:updates_document_type] if ret.dig(:ext, :updates_document_type)
10
+ unless ret.dig(:ext, :accessibility_color_inside).nil?
11
+ ret[:accessibility_color_inside] = ret[:ext][:accessibility_color_inside]
12
+ end
13
+ ret[:price_code] = ret[:ext][:price_code] if ret.dig(:ext, :price_code)
14
+ ret[:cen_processing] = ret[:ext][:cen_processing] unless ret.dig(:ext, :cen_processing).nil?
15
+ ret[:secretary] = ret[:ext][:secretary] if ret.dig(:ext, :secretary)
16
+ ret[:interest_to_committees] = ret[:ext][:interest_to_committees] if ret.dig(:ext, :interest_to_committees)
17
+ ret
18
+ end
19
+
6
20
  #
7
21
  # Ovverides superclass's method
8
22
  #
@@ -5,7 +5,7 @@ module RelatonIec
5
5
  FUNCTION = %w[emc safety enviroment quality-assurance].freeze
6
6
 
7
7
  # @return [String, nil]
8
- attr_reader :function, :updates_document_type, :price_code, :secretary,
8
+ attr_reader :function, :updates_document_type, :secretary,
9
9
  :interest_to_committees
10
10
 
11
11
  # @return [Boolean, nil]
@@ -43,7 +43,6 @@ module RelatonIec
43
43
  @function = args.delete :function
44
44
  @updates_document_type = args.delete :updates_document_type
45
45
  @accessibility_color_inside = args.delete :accessibility_color_inside
46
- @price_code = args.delete :price_code
47
46
  @cen_processing = args.delete :cen_processing
48
47
  @secretary = args.delete :secretary
49
48
  @interest_to_committees = args.delete :interest_to_committees
@@ -103,20 +102,24 @@ module RelatonIec
103
102
  # @return [Hash]
104
103
  def to_hash(embedded: false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
105
104
  hash = super
106
- hash["function"] = function if function
105
+ hash["ext"]["function"] = function if function
107
106
  if updates_document_type
108
- hash["updates_document_type"] = updates_document_type
107
+ hash["ext"]["updates_document_type"] = updates_document_type
109
108
  end
110
109
  unless accessibility_color_inside.nil?
111
- hash["accessibility_color_inside"] = accessibility_color_inside
110
+ hash["ext"]["accessibility_color_inside"] = accessibility_color_inside
112
111
  end
113
- hash["price_code"] = price_code if price_code
114
- hash["cen_processing"] = cen_processing unless cen_processing.nil?
115
- hash["secretary"] = secretary if secretary
112
+ hash["ext"]["cen_processing"] = cen_processing unless cen_processing.nil?
113
+ hash["ext"]["secretary"] = secretary if secretary
116
114
  if interest_to_committees
117
- hash["interest_to_committees"] = interest_to_committees
115
+ hash["ext"]["interest_to_committees"] = interest_to_committees
118
116
  end
119
117
  hash
120
118
  end
119
+
120
+ def has_ext?
121
+ super || function || updates_document_type || !accessibility_color_inside.nil? ||
122
+ !cen_processing.nil? || secretary || interest_to_committees
123
+ end
121
124
  end
122
125
  end
@@ -122,9 +122,11 @@ module RelatonIec
122
122
  # @return [Hash] index content
123
123
  #
124
124
  def get_index_from_gh # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
125
- resp = Zip::InputStream.new URI("#{Hit::GHURL}index.zip").open
126
- zip = resp.get_next_entry
127
- yaml = zip.get_input_stream.read
125
+ url = "#{Hit::GHURL}index.zip"
126
+ resp = Mechanize.new.get(url)
127
+ zip = Zip::InputStream.new(StringIO.new(resp.body))
128
+ entry = zip.get_next_entry
129
+ yaml = entry.get_input_stream.read
128
130
  index = RelatonBib.parse_yaml yaml, [Symbol]
129
131
  File.write path, index.to_yaml, encoding: "UTF-8"
130
132
  index
@@ -1,3 +1,3 @@
1
1
  module RelatonIec
2
- VERSION = "1.19.1".freeze
2
+ VERSION = "1.20.1".freeze
3
3
  end
@@ -13,7 +13,6 @@ module RelatonIec
13
13
  data[:updates_document_type] = ext.at("./updates-document-type")&.text
14
14
  aci = ext.at("./accessibility-color-inside")
15
15
  data[:accessibility_color_inside] = aci.text == "true" if aci
16
- data[:price_code] = ext.at("./price-code")&.text
17
16
  cp = ext.at("./cen-processing")
18
17
  data[:cen_processing] = cp.text == "true" if cp
19
18
  data[:secretary] = ext.at("./secretary")&.text
data/lib/relaton_iec.rb CHANGED
@@ -3,6 +3,7 @@ require "net/http"
3
3
  require "nokogiri"
4
4
  require "zip"
5
5
  require "open-uri"
6
+ require "mechanize"
6
7
  require "relaton/index"
7
8
  require "relaton_iso_bib"
8
9
  require "relaton_iec/hit"
data/relaton_iec.gemspec CHANGED
@@ -25,7 +25,8 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_dependency "addressable"
27
27
  spec.add_dependency "base64"
28
+ spec.add_dependency "mechanize", "~> 2.8"
28
29
  spec.add_dependency "relaton-index", "~> 0.2.0"
29
- spec.add_dependency "relaton-iso-bib", "~> 1.19.0"
30
+ spec.add_dependency "relaton-iso-bib", "~> 1.20.0"
30
31
  spec.add_dependency "rubyzip"
31
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-iec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.1
4
+ version: 1.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-01 00:00:00.000000000 Z
11
+ date: 2026-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mechanize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.8'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: relaton-index
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +72,14 @@ dependencies:
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 1.19.0
75
+ version: 1.20.0
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 1.19.0
82
+ version: 1.20.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubyzip
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -93,6 +107,7 @@ files:
93
107
  - ".gitignore"
94
108
  - ".rspec"
95
109
  - ".rubocop.yml"
110
+ - CLAUDE.md
96
111
  - Gemfile
97
112
  - LICENSE.txt
98
113
  - README.adoc
@@ -143,7 +158,7 @@ homepage: https://github.com/relaton/relaton-iec
143
158
  licenses:
144
159
  - MIT
145
160
  metadata: {}
146
- post_install_message:
161
+ post_install_message:
147
162
  rdoc_options: []
148
163
  require_paths:
149
164
  - lib
@@ -158,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
173
  - !ruby/object:Gem::Version
159
174
  version: '0'
160
175
  requirements: []
161
- rubygems_version: 3.3.27
162
- signing_key:
176
+ rubygems_version: 3.5.22
177
+ signing_key:
163
178
  specification_version: 4
164
179
  summary: 'RelatonIec: retrieve IEC Standards for bibliographic use using the IecBibliographicItem
165
180
  model'