Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Aug 21, 2020
1 parent 9f3afc0 commit 352f881
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 6 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
10 changes: 10 additions & 0 deletions lib/relaton_iho/comment_periond.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,15 @@ def to_hash
hash["to"] = to.to_s if to
hash
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix)
pref = prefix.empty? ? prefix : prefix + "."
pref += "commentperiod"
out = "#{pref}.from:: #{from}\n"
out += "#{pref}.to:: #{to}\n" if to
out
end
end
end
20 changes: 19 additions & 1 deletion lib/relaton_iho/editorial_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class EditorialGroupCollection

def_delegators :@collection, :first, :any?

# @return [Array<RelatonIho::editorialgroup]
# @return [Array<RelatonIho::EditorialGroup]
attr_reader :collection

# @param collection [Array<RelatonIho::EditorialGroup>]
Expand All @@ -23,6 +23,12 @@ def to_hash
single_element_array collection
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix)
collection.map { |ed| ed.to_asciibib prefix, collection.size }.join
end

# @return [Boolean]
def presence?
any?
Expand Down Expand Up @@ -60,5 +66,17 @@ def to_hash
hash["workgroup"] = workgroup if workgroup
hash
end

# @param prefix [String]
# @param count [Integer]
# @return [Strin]
def to_asciibib(prefix, count)
pref = prefix.empty? ? prefix : prefix + "."
pref += "editorialgroup"
out = count > 1 ? "#{pref}::\n" : ""
out += "#{pref}.committee:: #{committee}\n"
out += "#{pref}.workgroup:: #{workgroup}\n" if workgroup
out
end
end
end
10 changes: 9 additions & 1 deletion lib/relaton_iho/iho_bibliographic_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(**args)

# @param builder [Nokogiri::XML::Builder]
# @param bibdata [TrueClasss, FalseClass, NilClass]
def to_xml(builer = nil, **opts)
def to_xml(builer = nil, **opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
opts[:ext] = !commentperiod.nil?
super do |b|
if opts[:bibdata] && (doctype || editorialgroup&.presence? ||
Expand All @@ -36,5 +36,13 @@ def to_hash
hash["commentperiod"] = commentperiod.to_hash if commentperiod
hash
end

# @param prefix [String]
# @return [String]
def to_asciibib(prefix = "")
out = super
out += commentperiod.to_asciibib prefix if commentperiod
out
end
end
end
2 changes: 1 addition & 1 deletion lib/relaton_iho/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonIho
VERSION = "1.2.3".freeze
VERSION = "1.3.0".freeze
end
2 changes: 1 addition & 1 deletion relaton_iho.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "vcr"
s.add_development_dependency "webmock"

s.add_dependency "relaton-bib", "~> 1.2.0"
s.add_dependency "relaton-bib", "~> 1.3.0"
end
62 changes: 62 additions & 0 deletions spec/fixtures/asciibib.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[%bibitem]
== {blank}
id:: B-11
fetched:: 2020-03-29
type:: standard
docid.type:: IHO
docid.id:: B-11
docnumber:: 11
edition:: 1.0.0
language:: en
language:: fr
script:: Latn
version.revision_date:: 2019-10-31
docstatus.stage:: in-force
date.type:: published
date.from:: 2020-01-20
copyright::
copyright.owner.name.conten:: International Hydrographic Organization
copyright.owner.abbreviation.conten:: IHO
copyright.owner.url:: www.iho.int
copyright.role.type:: publisher
copyright.from:: 2019
copyright::
copyright.owner.name.conten:: Intergovernmental Oceanographic Commission
copyright.owner.abbreviation.conten:: IOC
copyright.owner.url:: http://ioc-unesco.org
copyright.role.type:: publisher
copyright.from:: 2019
link.type:: pdf
link.content:: https://www.star.nesdis.noaa.gov/socd/lsa/GEBCO_Cookbook/documents/CookBook_20191031.pdf
place.name:: Monaco
validity.begins:: 2019-10-31 00:00
contributor::
contributor.organization.name.conten:: International Hydrographic Organization
contributor.organization.abbreviation.conten:: IHO
contributor.organization.url:: www.iho.int
contributor::
contributor.organization.name.conten:: Intergovernmental Oceanographic Commission
contributor.organization.abbreviation.conten:: IOC
contributor.organization.url:: http://ioc-unesco.org
series.type:: main
series.title.type:: original
series.title.variant::
series.title.variant.conten:: Bathymetric Publications
series.title.variant.language:: en
series.title.variant.script:: Latn
series.title.variant::
series.title.variant.conten:: Publications bathymétriques
series.title.variant.language:: fr
series.title.variant.script:: Latn
series.title.format:: text/plain
series.place:: Monaco
series.organization:: International Hydrographic Organization
series.number:: B
editorialgroup::
editorialgroup.committee:: hssc
editorialgroup.workgroup:: WG1
editorialgroup::
editorialgroup.committee:: irss
editorialgroup.workgroup:: WG2
commentperiod.from:: 2011-01-01
commentperiod.to:: 2011-12-31
10 changes: 10 additions & 0 deletions spec/relaton_iho/iho_bibliography_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@
RelatonIho::IhoBibliography.search "ref"
end.to raise_error RelatonBib::RequestError
end

it "returns AsciiBib" do
hash = YAML.load_file "spec/fixtures/iho.yaml"
bib_hash = RelatonIho::HashConverter.hash_to_bib hash
item = RelatonIho::IhoBibliographicItem.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")
end
end

0 comments on commit 352f881

Please sign in to comment.