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 9fc2b81 commit 787a239
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 26 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
11 changes: 11 additions & 0 deletions lib/relaton_ogc/editorial_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ def to_hash
hash
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix)
pref = prefix.empty? ? prefix : prefix + "."
pref += "editorialgroup"
out = "#{pref}.committee:: #{committee}\n"
out += subcommittee.to_asciibib "#{pref}.subcommittee" if subcommittee
out += workgroup.to_asciibib "#{pref}.workgroup" if workgroup
out
end

private

# @param group [Hash, RelatonIsoBib::IsoSubgroup]
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_ogc/hash_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def editorialgroup_hash_to_bib(ret)
committee: eg[:committee],
subcommittee: eg[:subcommittee],
workgroup: eg[:workgroup],
secretariat: eg[:secretariat],
secretariat: eg[:secretariat]
)
end
end
Expand Down
12 changes: 11 additions & 1 deletion lib/relaton_ogc/ogc_bibliographic_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class OgcBibliographicItem < RelatonBib::BibliographicItem
# @param docsubtype [String]
def initialize(**args)
if args[:docsubtype] && !SUBTYPES.include?(args[:docsubtype])
warn "[relaton-ogc] WARNING: invalid document subtype: #{args[:docsubtype]}"
warn "[relaton-ogc] WARNING: invalid document "\
"subtype: #{args[:docsubtype]}"
end

@docsubtype = args.delete :docsubtype
Expand Down Expand Up @@ -48,5 +49,14 @@ def to_xml(builder = nil, **opts)
end
end
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix = "")
pref = prefix.empty? ? prefix : prefix + "."
out = super
out += "#{pref}docsubtype:: #{docsubtype}\n" if docsubtype
out
end
end
end
2 changes: 1 addition & 1 deletion lib/relaton_ogc/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonOgc
VERSION = "1.2.0".freeze
VERSION = "1.3.0".freeze
end
15 changes: 1 addition & 14 deletions lib/relaton_ogc/xml_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@
module RelatonOgc
class XMLParser < RelatonIsoBib::XMLParser
class << self
# Override RelatonIsoBib::XMLParser.form_xml method.
# @param xml [String]
# @return [RelatonOgc::OgcBibliographicItem]
# def from_xml(xml)
# doc = Nokogiri::XML(xml)
# item = doc.at "/bibitem|/bibdata"
# if item
# OgcBibliographicItem.new item_data(item)
# else
# warn "[relaton-ogc] can't find bibitem or bibdata element in the XML"
# end
# end

private

# override RelatonIsoBib::IsoBibliographicItem.bib_item method
Expand Down Expand Up @@ -48,7 +35,7 @@ def fetch_editorialgroup(ext)
sc = iso_subgroup eg&.at("subcommittee")
wg = iso_subgroup eg&.at("workgroup")
EditorialGroup.new(
committee: committe, subcommittee: sc, workgroup: wg,
committee: committe, subcommittee: sc, workgroup: wg
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion relaton_ogc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "webmock"

spec.add_dependency "faraday", "~> 1.0.0"
spec.add_dependency "relaton-iso-bib", "~> 1.2.0"
spec.add_dependency "relaton-iso-bib", "~> 1.3.0"
end
54 changes: 54 additions & 0 deletions spec/fixtures/asciibib.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[%bibitem]
== {blank}
id:: 19-025r1
fetched:: 2019-11-01
title::
title.type:: title-main
title.conten:: Development of Spatial Data Infrastructures for Marine Data Management
title.language:: en
title.script:: Latn
title.format:: text/plain
title::
title.type:: main
title.conten:: Development of Spatial Data Infrastructures for Marine Data Management
title.language:: en
title.script:: Latn
title.format:: text/plain
type:: public-engineering-report
docid.type:: OGC
docid.id:: 19-025r1
edition:: 1
language:: en
script:: Latn
date.type:: published
date.on:: 2019-01-01
abstract.conten:: This engineering report presents the results of a concept development study on a
Marine Spatial Data Infrastructure (SDI), sponsored by the National Geospatial-
Intelligence Agency (NGA) - Maritime Safety Office (MSO), on behalf of the
International Hydrographic Organization (IHO) and the IHO MSDI Working Group
(MSDIWG), and executed by the Open Geospatial Consortium (OGC). The goal of
this study was to demonstrate to stakeholders the diversity, richness and value of a
Marine SDI – specifically data, analysis, interoperability and associated IT services
- including web services - in addressing needs of the marine domain.
abstract.language:: en
abstract.script:: Latn
abstract.format:: text/plain
link.type:: obp
link.content:: https://portal.opengeospatial.org/files/?artifact_id=88037
contributor::
contributor.person.completename.conten:: Robert Thomas
contributor.role.type:: author
contributor::
contributor.person.completename.conten:: Terry Idol
contributor.role.type:: author
contributor::
contributor.organization.name.conten:: Open Geospatial Consortium
contributor.role.type:: publisher
editorialgroup.committee:: technical
editorialgroup.subcommittee.type:: OGC
editorialgroup.subcommittee.number:: 11
editorialgroup.subcommittee.name:: Subcommittee
editorialgroup.workgroup.type:: WG
editorialgroup.workgroup.number:: 22
editorialgroup.workgroup.name:: Working
docsubtype:: Document subtype
1 change: 1 addition & 0 deletions spec/fixtures/ogc_bib_item.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ editorialgroup:
name: Working
type: WG
number: 22
docsubtype: Document subtype
3 changes: 2 additions & 1 deletion spec/relaton_ogc/hit_collection_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
RSpec.describe RelatonOgc::HitCollection do
it "fetch data from server" do
expect(File).to receive(:ctime).and_return(Date.today.prev_day.to_time).at_most(:once)
expect(File).to receive(:ctime).and_return(Date.today.prev_day.to_time)
.at_most(:once)
expect(File).to receive(:write).twice
expect(File).to receive(:read).with(
RelatonOgc::HitCollection::ETAGFILE, encoding: "UTF-8"
Expand Down
11 changes: 11 additions & 0 deletions spec/relaton_ogc/ogc_bibliographic_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
RelatonOgc::OgcBibliographicItem.new docsubtype: "invalid-subtype"
end.to output(/invalid document subtyp/).to_stderr
end

it "returns AciiBib" do
hash = YAML.load_file "spec/fixtures/ogc_bib_item.yml"
bib_hash = RelatonOgc::HashConverter.hash_to_bib hash
item = RelatonOgc::OgcBibliographicItem.new bib_hash
bib = item.to_asciibib
file = "spec/fixtures/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{2/, Date.today.to_s)
end
end
12 changes: 7 additions & 5 deletions spec/relaton_ogc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
path = "spec/fixtures/hit.xml"
xml = hits.first.to_xml bibdata: true
File.write path, xml, encoding: "UTF-8" unless File.exist? path
expect(xml).to be_equivalent_to File.open(path, "r:UTF-8", &:read).
gsub(/(?<=<fetched>)\d{4}-\d{2}-\d{2}/, Date.today.to_s)
expect(xml).to be_equivalent_to File.open(path, "r:UTF-8", &:read)
.gsub(/(?<=<fetched>)\d{4}-\d{2}-\d{2}/, Date.today.to_s)
schema = Jing.new "spec/fixtures/isobib.rng"
errors = schema.validate path
expect(errors).to eq []
Expand Down Expand Up @@ -57,7 +57,9 @@
expect do
result = RelatonOgc::OgcBibliography.get "OGC 19-025r1", "2018", {}
expect(result).to be_nil
end.to output(%r{WARNING: no match found online for OGC 19-025r1 year 2018}).to_stderr
end.to output(
%r{WARNING: no match found online for OGC 19-025r1 year 2018}
).to_stderr
end
end

Expand All @@ -67,8 +69,8 @@
result = RelatonOgc::OgcBibliography.get "12-128r14", nil, {}
xml = result.to_xml bibdata: true
File.write path, xml, encoding: "UTF-8" unless File.exist? path
expect(xml).to be_equivalent_to File.read(path, encoding: "UTF-8").
sub /(?<=<fetched>)\d{4}-\d{2}-\d{2}/, Date.today.to_s
expect(xml).to be_equivalent_to File.read(path, encoding: "UTF-8")
.sub /(?<=<fetched>)\d{4}-\d{2}-\d{2}/, Date.today.to_s
schema = Jing.new "spec/fixtures/isobib.rng"
errors = schema.validate path
expect(errors).to eq []
Expand Down

0 comments on commit 787a239

Please sign in to comment.