Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Oct 18, 2023
1 parent b1acedb commit a803651
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 34 deletions.
17 changes: 14 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,24 @@ Or install it yourself as:

== Usage

=== Search for a standard using keywords
=== Configuration

Configuration is optional. The available option is `logger` which is a `Logger` instance. By default, the logger is `Logger.new($stderr)` with `Logger::WARN` level. To change the logger level, use `RelatonXsf.configure` block.

[source,ruby]
----
require 'relaton_xsf'
=> true
RelatonXsf.configure do |config|
config.logger.level = Logger::DEBUG
end
----

=== Search for a standard using keywords

[source,ruby]
----
hit_collection = RelatonXsf::Bibliography.search("XEP 0001")
=> <RelatonXsf::HitCollection:0x00000000019780 @ref=XEP 0001 @fetched=false>
Expand Down Expand Up @@ -81,8 +92,8 @@ item.to_xml bibdata: true
[source,ruby]
----
item = RelatonXsf::Bibliography.get "XEP 0001"
[relaton-xsf] (XEP 0001) fetching...
[relaton-xsf] (XEP 0001) found XEP 0001
[relaton-xsf] (XEP 0001) Fetching from Relaton repository ...
[relaton-xsf] (XEP 0001) Found `XEP 0001`
=> #<RelatonXsf::BibliographicItem:0x000000011275cd18
...
Expand Down
6 changes: 3 additions & 3 deletions lib/relaton_xsf/bibliography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ def search(ref)
end

def get(code, _year = nil, _opts = {})
Util.warn "(#{code}) fetching..."
Util.warn "(#{code}) Fetching from Relaton repository ..."
result = search(code)
if result.empty?
Util.warn "(#{code}) nothing found"
Util.warn "(#{code}) Not found."
return
end

bib = result.first.fetch
Util.warn "(#{code}) found `#{bib.docidentifier.first.id}`"
Util.warn "(#{code}) Found: `#{bib.docidentifier.first.id}`"
bib
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_xsf/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RelatonXsf
VERSION = "1.16.1"
VERSION = "1.16.2"
end
23 changes: 15 additions & 8 deletions spec/relaton_xsf/xsf_bibliography_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@

context "get" do
it "successful", vcr: "get_successful" do
file = "spec/fixtures/bibdata.xml"
bib = RelatonXsf::Bibliography.get "XEP 0001"
xml = bib.to_xml bibdata: true
File.write file, xml, encoding: "UTF-8" unless File.exist? file
expect(bib).to be_instance_of RelatonXsf::BibliographicItem
expect(bib.docidentifier.first.id).to eq "XEP 0001"
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 do
file = "spec/fixtures/bibdata.xml"
bib = RelatonXsf::Bibliography.get "XEP 0001"
xml = bib.to_xml bibdata: true
File.write file, xml, encoding: "UTF-8" unless File.exist? file
expect(bib).to be_instance_of RelatonXsf::BibliographicItem
expect(bib.docidentifier.first.id).to eq "XEP 0001"
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.to output(
include("[relaton-xsf] (XEP 0001) Fetching from Relaton repository ...",
"[relaton-xsf] (XEP 0001) Found: `XEP 0001`"),
).to_stderr
end

it "not found", vcr: "get_not_found" do
expect { RelatonXsf::Bibliography.get "XEP nope" }.to output(
/\[relaton-xsf\] \(XEP nope\) nothing found/,
/\[relaton-xsf\] \(XEP nope\) Not found\./,
).to_stderr
end
end
Expand Down
38 changes: 19 additions & 19 deletions spec/vcr_cassettes/get_successful.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a803651

Please sign in to comment.