Skip to content

Commit

Permalink
update Nokogiri to v1.15 & doctype model
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Nov 27, 2023
1 parent 45b005c commit 2d71db9
Show file tree
Hide file tree
Showing 20 changed files with 3,062 additions and 2,812 deletions.
Binary file added 3185.zip
Binary file not shown.
20 changes: 18 additions & 2 deletions grammars/basicdoc.rng
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@
<ref name="keyword"/>
<ref name="xref"/>
<ref name="hyperlink"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</oneOrMore>
</element>
Expand Down Expand Up @@ -623,6 +625,8 @@
<ref name="eref"/>
<ref name="xref"/>
<ref name="hyperlink"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</zeroOrMore>
</element>
Expand All @@ -636,6 +640,8 @@
<ref name="eref"/>
<ref name="xref"/>
<ref name="hyperlink"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</zeroOrMore>
</element>
Expand All @@ -648,14 +654,20 @@
<ref name="eref"/>
<ref name="xref"/>
<ref name="hyperlink"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</zeroOrMore>
</element>
</define>
<define name="keyword">
<element name="keyword">
<zeroOrMore>
<ref name="PureTextElement"/>
<choice>
<ref name="PureTextElement"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</zeroOrMore>
</element>
</define>
Expand All @@ -676,7 +688,11 @@
<define name="strike">
<element name="strike">
<zeroOrMore>
<ref name="PureTextElement"/>
<choice>
<ref name="PureTextElement"/>
<ref name="index"/>
<ref name="index-xref"/>
</choice>
</zeroOrMore>
</element>
</define>
Expand Down
1 change: 1 addition & 0 deletions grammars/biblio.rng
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@
<value>obsoleted</value>
<value>confirmed</value>
<value>updated</value>
<value>corrected</value>
<value>issued</value>
<value>transmitted</value>
<value>copied</value>
Expand Down
1 change: 1 addition & 0 deletions lib/relaton_ieee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require "relaton_ieee/version"
require "relaton_ieee/config"
require "relaton_ieee/util"
require "relaton_ieee/document_type"
require "relaton_ieee/document_status"
require "relaton_ieee/ieee_bibliography"
require "relaton_ieee/ieee_bibliographic_item"
Expand Down
19 changes: 14 additions & 5 deletions lib/relaton_ieee/data_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,25 @@ def parse_contributor # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
doc.xpath("./publicationinfo/publisher").map do |contrib|
n = contrib.at("./publishername").text
addr = contrib.xpath("./address").each_with_object([]) do |adr, ob|
city = adr.at("./city")
next unless city
city, country, state = parse_country_city adr
next unless city && country

ob << RelatonBib::Address.new(street: [], city: city.text,
country: adr.at("./country").text)
ob << RelatonBib::Address.new(street: [], city: city, state: state, country: country)
end
e = create_org n, addr
RelatonBib::ContributionInfo.new entity: e, role: [type: "publisher"]
end
end

def parse_country_city(address)
city = address.at("./city")
return unless city

city, state = city.text.split(", ")
country = address.at("./country")&.text || "USA"
[city, country, state]
end

#
# Create organization
#
Expand Down Expand Up @@ -335,7 +343,8 @@ def parse_holdstatus
# @return [String] doctype
#
def parse_doctype
parse_standard_modified == "Redline" ? "redline" : "standard"
type = parse_standard_modified == "Redline" ? "redline" : "standard"
DocumentType.new type: type
end
end
end
17 changes: 17 additions & 0 deletions lib/relaton_ieee/document_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module RelatonIeee
class DocumentType < RelatonBib::DocumentType
DOCTYPES = %w[guide recommended-practice standard witepaper redline other].freeze

def initialize(type:, abbreviation: nil)
check_type type
super
end

def check_type(type)
unless DOCTYPES.include? type
Util.warn "Invalid doctype: `#{type}`. " \
"It should be one of: `#{DOCTYPES.join('`, `')}`."
end
end
end
end
62 changes: 33 additions & 29 deletions lib/relaton_ieee/hash_converter.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
module RelatonIeee
class HashConverter < RelatonBib::HashConverter
class << self
# @param args [Hash]
# @param neated [TrueClas, FalseClass] default true
# @return [Hash]
def hash_to_bib(args)
hash = super
return unless hash.is_a?(Hash)
module HashConverter
include RelatonBib::HashConverter
extend self
# @param args [Hash]
# @param neated [TrueClas, FalseClass] default true
# @return [Hash]
def hash_to_bib(args)
hash = super
return unless hash.is_a?(Hash)

# editorialgroup_hash_to_bib hash
ext_hash_to_bib hash
hash
end
# editorialgroup_hash_to_bib hash
ext_hash_to_bib hash
hash
end

# @param item_hash [Hash]
# @return [RelatonIeee::IeeeBibliographicItem]
def bib_item(item_hash)
IeeeBibliographicItem.new(**item_hash)
end
# @param item_hash [Hash]
# @return [RelatonIeee::IeeeBibliographicItem]
def bib_item(item_hash)
IeeeBibliographicItem.new(**item_hash)
end

# @param hash [Hash]
def editorialgroup_hash_to_bib(hash)
return unless hash[:editorialgroup]
# @param hash [Hash]
def editorialgroup_hash_to_bib(hash)
return unless hash[:editorialgroup]

hash[:editorialgroup] = EditorialGroup.new(**hash[:editorialgroup])
end
hash[:editorialgroup] = EditorialGroup.new(**hash[:editorialgroup])
end

def ext_hash_to_bib(hash)
ext = hash.delete(:ext)
return unless ext
def ext_hash_to_bib(hash)
ext = hash.delete(:ext)
return unless ext

attrs = %i[standard_status standard_modified pubstatus holdstatus]
ext.select { |k, _| attrs.include? k }.each do |k, v|
hash[k] = v
end
attrs = %i[standard_status standard_modified pubstatus holdstatus]
ext.select { |k, _| attrs.include? k }.each do |k, v|
hash[k] = v
end
end

def create_doctype(**args)
DocumentType.new(**args)
end
end
end
7 changes: 1 addition & 6 deletions lib/relaton_ieee/ieee_bibliographic_item.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module RelatonIeee
class IeeeBibliographicItem < RelatonBib::BibliographicItem
DOCTYPES = %w[guide recommended-practice standard witepaper redline other].freeze
SUBTYPES = %w[amendment corrigendum erratum].freeze

# @return [RelatonIeee::EditorialGroup, nil]
Expand All @@ -24,10 +23,6 @@ class IeeeBibliographicItem < RelatonBib::BibliographicItem
# @option args [String, nil] :holdstatus Held, Publish
#
def initialize(**args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
if args[:doctype] && !DOCTYPES.include?(args[:doctype])
Util.warn "Invalid doctype: `#{args[:doctype]}`. " \
"It should be one of: `#{DOCTYPES.join('`, `')}`."
end
if args[:docsubtype] && !SUBTYPES.include?(args[:docsubtype])
Util.warn "Invalid docsubtype: `#{args[:docsubtype]}`. " \
"It should be one of: `#{SUBTYPES.join('`, `')}`."
Expand Down Expand Up @@ -68,7 +63,7 @@ def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metr
if opts[:bibdata] && (doctype || subdoctype || !trialuse.nil? || editorialgroup ||
ics.any? || standard_status || standard_modified || pubstatus || holdstatus)
ext = bldr.ext do |b|
b.doctype doctype if doctype
doctype&.to_xml b
b.subdoctype subdoctype if subdoctype
b.send :"trial-use", trialuse unless trialuse.nil?
editorialgroup&.to_xml(b)
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_ieee/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonIeee
VERSION = "1.16.3".freeze
VERSION = "1.17.0".freeze
end
2 changes: 1 addition & 1 deletion relaton_ieee.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "faraday", "~> 2.7.0"
spec.add_dependency "mini_portile2", "~> 2.8.0"
spec.add_dependency "relaton-bib", "~> 1.16.0"
spec.add_dependency "relaton-bib", "~> 1.17.0"
spec.add_dependency "relaton-index", "~> 0.2.0"
spec.add_dependency "rubyzip", "~> 2.3.0"
end
2 changes: 1 addition & 1 deletion spec/fixtures/ieee-std.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.4">
<bibdata type="standard" schema-version="v1.2.5">
<title type="main" format="text/plain">IEEE Draft Supplement to Information technology Telecommunications and information exchange between systems Local and metropolitan area networks Part 5: Token Ring access method and physical layer specifications 100 Mbit/s Dedicated Token Ring Operation (Supplement to ISO/IEC 8802-5:1998 and ISO/IEC 8802-5:1998/Amd.1:1998)</title>
<uri type="src">https://ieeexplore.ieee.org/document/4039945</uri>
<docidentifier type="IEEE" primary="true">IEEE P802.5t/D-2.5</docidentifier>
Expand Down
5 changes: 3 additions & 2 deletions spec/fixtures/ieee-std.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
schema-version: v1.2.4
schema-version: v1.2.5
id: IEEEP802.5t-D-2.5
title:
- content: 'IEEE Draft Supplement to Information technology Telecommunications and
Expand Down Expand Up @@ -52,7 +52,8 @@ copyright:
contact:
- uri: http://www.ieee.org
from: '1998'
doctype: standard
doctype:
type: standard
ics:
- code: '35.110'
text: Networking
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/ieee_528_2019.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bibdata type="standard" schema-version="v1.2.4">
<bibdata type="standard" schema-version="v1.2.5">
<fetched>2023-05-16</fetched>
<title type="main" format="text/plain">IEEE Standard for Inertial Sensor Terminology</title>
<uri type="src">https://ieeexplore.ieee.org/document/8863799</uri>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/ieee_528_2019.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: IEEE528-2019
schema-version: v1.2.4
schema-version: v1.2.5
title:
- type: main
content: IEEE Standard for Inertial Sensor Terminology
Expand Down
33 changes: 33 additions & 0 deletions spec/relaton_ieee/data_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,39 @@
end
end

context "parse country city" do
it "without city" do
doc = Nokogiri::XML <<~XML
<address>
<country>USA</country>
</address>
XML
addr = doc.at "/address"
expect(subject.parse_country_city(addr)).to be_nil
end

it "with city, state, and country" do
doc = Nokogiri::XML <<~XML
<address>
<city>City, State</city>
<country>Country</country>
</address>
XML
addr = doc.at "/address"
expect(subject.parse_country_city(addr)).to eq ["City", "Country", "State"]
end

it "use USA as default country" do
doc = Nokogiri::XML <<~XML
<address>
<city>City</city>
</address>
XML
addr = doc.at "/address"
expect(subject.parse_country_city(addr)).to eq ["City", "USA", nil]
end
end

context "create organization" do
it "ANSI" do
org = subject.create_org("ANSI")
Expand Down
12 changes: 12 additions & 0 deletions spec/relaton_ieee/document_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe RelatonIeee::DocumentType do
before { RelatonIeee.instance_variable_set :@configuration, nil }

it "warn when doctype is invalid" do
expect do
described_class.new type: "invalid"
end.to output(
"[relaton-ieee] Invalid doctype: `invalid`. It should be one of: " \
"`guide`, `recommended-practice`, `standard`, `witepaper`, `redline`, `other`.\n",
).to_stderr_from_any_process
end
end
14 changes: 2 additions & 12 deletions spec/relaton_ieee/ieee_bibliographic_item_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
RSpec.describe RelatonIeee::IeeeBibliographicItem do
let(:type) { "invalid" }
before { RelatonIeee.instance_variable_set :@configuration, nil }

it "returns AsciiBib" do
Expand All @@ -13,20 +12,11 @@
expect(bib).to eq File.read(file, encoding: "UTF-8")
end

it "warn when doctype is invalid" do
expect do
described_class.new doctype: type
end.to output(
"[relaton-ieee] Invalid doctype: `#{type}`. It should be one of: " \
"`guide`, `recommended-practice`, `standard`, `witepaper`, `redline`, `other`.\n",
).to_stderr
end

it "warn when subdoctype is invalid" do
expect do
described_class.new docsubtype: type
described_class.new docsubtype: "invalid"
end.to output(
"[relaton-ieee] Invalid docsubtype: `#{type}`. It should be one of: " \
"[relaton-ieee] Invalid docsubtype: `invalid`. It should be one of: " \
"`amendment`, `corrigendum`, `erratum`.\n",
).to_stderr
end
Expand Down
Loading

0 comments on commit 2d71db9

Please sign in to comment.