Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Aug 20, 2020
1 parent cd71dff commit c4e910d
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
inherit_from:
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.4
Rails:
Enabled: true
Enabled: false
14 changes: 13 additions & 1 deletion lib/relaton_itu/editorial_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(bureau:, group:, subgroup: nil, workgroup: nil)
end

# @param builder [Nokogiri::XML::Builder]
def to_xml(builder)
def to_xml(builder) # rubocop:disable Metrics/AbcSize
builder.editorialgroup do
builder.bureau bureau
builder.group { |b| group.to_xml b } if group
Expand All @@ -43,5 +43,17 @@ def to_hash
hash["workgroup"] = workgroup.to_hash if workgroup
hash
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix) # rubocop:disable Metrics/AbcSize
pref = prefix.empty? ? prefix : prefix + "."
pref += "editorialgroup"
out = "#{pref}.bureau:: #{bureau}\n"
out += group.to_asciibib "#{pref}.group" if group
out += subgroup.to_asciibib "#{pref}.subgroup" if subgroup
out += workgroup.to_asciibib "#{pref}.workgroup" if workgroup
out
end
end
end
2 changes: 1 addition & 1 deletion lib/relaton_itu/hash_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def structuredidentifier_hash_to_bib(ret)
return unless ret[:structuredidentifier]

ret[:structuredidentifier] = StructuredIdentifier.new(
ret[:structuredidentifier],
ret[:structuredidentifier]
)
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/relaton_itu/itu_bibliographic_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ class ItuBibliographicItem < RelatonBib::BibliographicItem

# @params structuredidentifier [RelatonItu::StructuredIdentifier]
def initialize(**args)
# @doctype = args.delete :doctype
if args[:doctype] && !TYPES.include?(args[:doctype])
warn "[relaton-itu] WARNING: invalid doctype: #{args[:doctype]}"
end
super
# @doctype = args[:doctype]
end
end
end
8 changes: 0 additions & 8 deletions lib/relaton_itu/itu_bibliography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ def fetch_ref_err(code, year, missed_years)
nil
end

# def fetch_pages(hits, threads)
# workers = RelatonBib::WorkersPool.new threads
# workers.worker { |w| { i: w[:i], hit: w[:hit].fetch } }
# hits.each_with_index { |hit, i| workers << { i: i, hit: hit } }
# workers.end
# workers.result.sort_by { |a| a[:i] }.map { |x| x[:hit] }
# end

def search_filter(code)
docidrx = %r{\w+\.\d+|\w\sSuppl\.\s\d+} # %r{^ITU-T\s[^\s]+}
c = code.sub(/Imp\s?/, "").match(docidrx).to_s
Expand Down
21 changes: 21 additions & 0 deletions lib/relaton_itu/itu_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def to_hash
hash["finish"] = finish if finish
hash
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix)
pref = prefix.empty? ? prefix : prefix + "."
pref += "period"
out = "#{pref}.start:: #{start}\n"
out += "#{pref}.finish:: #{finish}\n" if finish
out
end
end

TYPES = %w[tsag study-group work-group].freeze
Expand Down Expand Up @@ -72,5 +82,16 @@ def to_hash
hash["period"] = period.to_hash if period
hash
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix)
pref = prefix.empty? ? prefix : prefix + "."
out = "#{pref}name:: #{name}\n"
out += "#{pref}type:: #{type}\n" if type
out += "#{pref}acronym:: #{acronym}\n" if acronym
out += period.to_asciibib prefix if period
out
end
end
end
10 changes: 10 additions & 0 deletions lib/relaton_itu/structured_identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def to_hash
hash
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix)
pref = prefix.empty? ? prefix : prefix + "."
pref += "structuredidentifier"
out = "#{pref}.bureau:: #{bureau}\n#{pref}.docnumber:: #{docnumber}\n"
out += "#{pref}.annexid:: #{annexid}\n" if annexid
out
end

def presence?
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_itu/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonItu
VERSION = "1.2.0".freeze
VERSION = "1.3.0".freeze
end
2 changes: 1 addition & 1 deletion relaton-itu.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "vcr", "~> 5.0.0"
spec.add_development_dependency "webmock"

spec.add_dependency "relaton-bib", "~> 1.2.0"
spec.add_dependency "relaton-bib", "~> 1.3.0"
end
54 changes: 54 additions & 0 deletions spec/examples/asciibib.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[%bibitem]
== {blank}
id:: ITU-T L.163 (11/2018)
fetched:: 2020-08-20
title.conten:: ITU-T L.163 (11/2018): Criteria for optical cable installation with minimal existing infrastructure
title.language:: en
title.script:: Latn
title.format:: text/plain
type:: standard
docid.type:: ITU-T
docid.id:: L.163
edition:: 1
language:: en
script:: Latn
docstatus.stage:: Published
date.type:: published
date.on:: 2018-01-01
abstract.conten:: Recommendation ITU-T L.163 describescriteria for the installation of optical fibre cables defined in [ITU-TL.110] in remote areas withlack of usual infrastructure for installation including the procedures ofcable-route planning, cable selection, cable-installation scheme selection,cable tension and temperature consideration, and the handling, bend protectionand river/lake closing of the cable together with pilot tests and training forinstallation.ThisRecommendation also describes how to mitigate the considerable risks and/orissues to which the optical fibre cable may be exposed when infrastructures areminimal during installation, maintenance and operation procedures.
abstract.language:: en
abstract.script:: Latn
abstract.format:: text/plain
copyright.owner.name.conten:: International Telecommunication Union
copyright.owner.abbreviation.conten:: ITU
copyright.owner.url:: www.itu.int
copyright.role.type:: publisher
copyright.from:: 2018
link::
link.type:: src
link.content:: https://www.itu.int/net4/ITU-T/search/api/redirection?dest=http%3A%2F%2Fhandle.itu.int%2F11.1002%2F1000%2F13786-en&amp;position=10&amp;page=1
link::
link.type:: obp
link.content:: https://www.itu.int/rec/T-REC-L.163-201811-P
contributor.organization.name.conten:: International Telecommunication Union
contributor.organization.abbreviation.conten:: ITU
contributor.organization.url:: www.itu.int
contributor.role.type:: publisher
relation::
relation.type:: complements
relation.bibitem.type:: standard
relation.bibitem.formattedref:: L Suppl. 4 (04/2016)
relation::
relation.type:: complements
relation.bibitem.type:: standard
relation.bibitem.formattedref:: L Suppl. 5 (12/2014)
doctype:: recommendation
editorialgroup.bureau:: T
editorialgroup.group.name:: ITU-T Study Group 15
editorialgroup.group.type:: study-group
editorialgroup.group.acronym:: SG
editorialgroup.group.period.start:: 2011
editorialgroup.group.period.finish:: 2012
structuredidentifier.bureau:: T
structuredidentifier.docnumber:: T.10
structuredidentifier.annexid:: 11
4 changes: 2 additions & 2 deletions spec/relaton_itu/hash_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
xml = item.to_xml bibdata: true
file = "spec/examples/from_yaml.xml"
File.write file, xml, encoding: "UTF-8" unless File.exist? file
expect(xml).to be_equivalent_to File.read(file, encoding: "UTF-8").
sub %r{(?<=<fetched>)\d{4}-\d{2}-\d{2}}, Date.today.to_s
expect(xml).to be_equivalent_to File.read(file, encoding: "UTF-8")
.sub %r{(?<=<fetched>)\d{4}-\d{2}-\d{2}}, Date.today.to_s
schema = Jing.new "spec/examples/isobib.rng"
errors = schema.validate file
expect(errors).to eq []
Expand Down
11 changes: 11 additions & 0 deletions spec/relaton_itu/itu_bibliographic_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@
item_hash = item.to_hash
expect(item_hash["editorialgroup"]).to eq hash["editorialgroup"]
end

it "returns AsciiBib" do
hash = YAML.load_file "spec/examples/itu_bib_item.yml"
item_hash = RelatonItu::HashConverter.hash_to_bib hash
item = RelatonItu::ItuBibliographicItem.new item_hash
bib = item.to_asciibib
file = "spec/examples/asciibib.adoc"
File.write file, bib, encoding: "UTF-8" unless File.exist? file
expect(bib).to eq File.read(file, encoding: "UTF-8")
.gsub(/(?<=fetched::\s)\d{4}-\d{2}-\d{3}/, Date.today.to_s)
end
end
21 changes: 12 additions & 9 deletions spec/relaton_itu/relaton_itu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
results = RelatonItu::ItuBibliography.get("ITU-T L.163", nil, {}).to_xml
expect(results).to include %(<bibitem id="ITU-TL.163" type="standard">)
expect(results).to include %(<on>2018</on>)
expect(results.gsub(/<relation.*<\/relation>/m, "")).not_to include %(<on>2018</on>)
expect(results).to include %(<docidentifier type="ITU">ITU-T L.163</docidentifier>)
expect(results.gsub(/<relation.*<\/relation>/m, ""))
.not_to include %(<on>2018</on>)
expect(results)
.to include %(<docidentifier type="ITU">ITU-T L.163</docidentifier>)
end
end

Expand Down Expand Up @@ -84,16 +86,16 @@
xml = result.to_xml
file = "spec/examples/itu_g_imp_712.xml"
File.write file, xml, encoding: "UTF-8" unless File.exist? file
expect(xml).to be_equivalent_to File.read(file, encoding: "UTF-8").
gsub /(?<=<fetched>)\d{4}-\d{2}-\d{2}/, Date.today.to_s
expect(xml).to be_equivalent_to File.read(file, encoding: "UTF-8")
.gsub /(?<=<fetched>)\d{4}-\d{2}-\d{2}/, Date.today.to_s
end
end

it "warns when year is wrong" do
VCR.use_cassette "wrong_year" do
expect { RelatonItu::ItuBibliography.get("ITU-T L.163", "1018", {}) }.
to output(%r{WARNING: no match found online for ITU-T L.163:1018.}).
to_stderr
expect { RelatonItu::ItuBibliography.get("ITU-T L.163", "1018", {}) }
.to output(%r{WARNING: no match found online for ITU-T L.163:1018.})
.to_stderr
end
end

Expand Down Expand Up @@ -139,7 +141,8 @@
expect(Net::HTTP).to receive(:post).with(
kind_of(URI), kind_of(String), kind_of(Hash)
).and_raise SocketError
expect { RelatonItu::ItuBibliography.search "ITU-T L.163" }.
to raise_error RelatonBib::RequestError
expect do
RelatonItu::ItuBibliography.search "ITU-T L.163"
end.to raise_error RelatonBib::RequestError
end
end

0 comments on commit c4e910d

Please sign in to comment.