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 eabd6cb commit 91cfaf1
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/relaton_jis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_relative "relaton_jis/version"
require_relative "relaton_jis/config"
require_relative "relaton_jis/util"
require_relative "relaton_jis/document_type"
require_relative "relaton_jis/bibliographic_item"
require_relative "relaton_jis/xml_parser"
require_relative "relaton_jis/hash_converter"
Expand Down
1 change: 0 additions & 1 deletion lib/relaton_jis/bibliographic_item.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module RelatonJis
class BibliographicItem < RelatonIsoBib::IsoBibliographicItem
DOCTYPES = %w[japanese-industrial-standard technical-report technical-specification amendment].freeze
#
# Fetch the flavor shcema version
#
Expand Down
16 changes: 16 additions & 0 deletions lib/relaton_jis/document_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module RelatonJis
class DocumentType < RelatonBib::DocumentType
DOCTYPES = %w[japanese-industrial-standard technical-report technical-specification amendment].freeze

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

def check_type(type)
unless DOCTYPES.include? type
Util.warn "WARNING: invalid doctype: `#{type}`"
end
end
end
end
11 changes: 9 additions & 2 deletions lib/relaton_jis/hash_converter.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
module RelatonJis
class HashConverter < RelatonBib::HashConverter
module HashConverter
include RelatonBib::HashConverter
extend self

# @param item_hash [Hash]
# @return [Relaton3gpp::BibliographicItem]
def self.bib_item(item_hash)
def bib_item(item_hash)
BibliographicItem.new(**item_hash)
end

def create_doctype(**args)
DocumentType.new(**args)
end
end
end
13 changes: 7 additions & 6 deletions lib/relaton_jis/scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ def fetch_docstatus
end

def fetch_doctype
case document_id
when /JIS\s[A-Z]\s[\w-]+:\d{4}\/AMENDMENT/ then "amendment"
when /JIS\s[A-Z]\s[\w-]+/ then "japanese-industrial-standard"
when /TR[\s\/][\w-]+/ then "technical-report"
when /TS[\s\/][\w-]+/ then "technical-specification"
end
type = case document_id
when /JIS\s[A-Z]\s[\w-]+:\d{4}\/AMENDMENT/ then "amendment"
when /JIS\s[A-Z]\s[\w-]+/ then "japanese-industrial-standard"
when /TR[\s\/][\w-]+/ then "technical-report"
when /TS[\s\/][\w-]+/ then "technical-specification"
end
DocumentType.new type: type
end

def fetch_ics
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_jis/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RelatonJis
VERSION = "1.16.8"
VERSION = "1.17.0"
end
2 changes: 1 addition & 1 deletion relaton_jis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Gem::Specification.new do |spec|

# Uncomment to register a new dependency of your gem
spec.add_dependency "mechanize", "~> 2.8.0"
spec.add_dependency "relaton-iso-bib", "~> 1.16.0"
spec.add_dependency "relaton-iso-bib", "~> 1.17.0"

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
Expand Down
7 changes: 7 additions & 0 deletions spec/relaton_jis/document_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe RelatonJis::DocumentType do
it "warn if type is not valid" do
expect do
RelatonJis::DocumentType.new type: "invalid"
end.to output(/\[relaton-jis\] WARNING: invalid doctype: `invalid`/).to_stderr
end
end
6 changes: 6 additions & 0 deletions spec/relaton_jis/hash_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
bib = described_class.bib_item title: [{ content: "title" }]
expect(bib).to be_instance_of(RelatonJis::BibliographicItem)
end

it "create_doctype" do
doctype = described_class.create_doctype type: "type"
expect(doctype).to be_instance_of RelatonJis::DocumentType
expect(doctype.type).to eq "type"
end
end
2 changes: 1 addition & 1 deletion spec/relaton_jis/scraper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
shared_examples "doctype" do |id, doctype|
it do
expect(subject).to receive(:document_id).and_return id
expect(subject.fetch_doctype).to eq doctype
expect(subject.fetch_doctype.type).to eq doctype
end
end

Expand Down

0 comments on commit 91cfaf1

Please sign in to comment.