Skip to content

Commit

Permalink
add license
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Feb 16, 2020
1 parent f60c76d commit 9e5b56b
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 9 deletions.
5 changes: 4 additions & 1 deletion lib/relaton_bib/bibliographic_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class BibliographicItem
attr_reader :extent

# @return [Array<Strig>]
attr_reader :accesslocation
attr_reader :accesslocation, :license

# @return [Array<Relaton::Classification>]
attr_reader :classification
Expand Down Expand Up @@ -227,6 +227,7 @@ def initialize(**args)
@validity = args[:validity]
@fetched = args.fetch :fetched, nil # , Date.today # we should pass the fetched arg from scrappers
@keyword = (args[:keyword] || []).map { |kw| LocalizedString.new(kw) }
@license = args.fetch :license, []
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
Expand Down Expand Up @@ -309,6 +310,7 @@ def to_hash
hash["validity"] = validity.to_hash if validity
hash["fetched"] = fetched.to_s if fetched
hash["keyword"] = single_element_array(keyword) if keyword&.any?
hash["license"] = single_element_array(license) if license&.any?
hash
end

Expand Down Expand Up @@ -526,6 +528,7 @@ def render_xml(builder, **opts)
place.each { |pl| pl.to_xml builder }
extent.each { |e| builder.extent { e.to_xml builder } }
accesslocation.each { |al| builder.accesslocation al }
license.each { |l| builder.license l }
classification.each { |cls| cls.to_xml builder }
keyword.each { |kw| builder.keyword { kw.to_xml(builder) } }
validity&.to_xml builder
Expand Down
2 changes: 2 additions & 0 deletions lib/relaton_bib/hash_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def hash_to_bib(args, nested = false)
accesslocation_hash_to_bib(ret)
classification_hash_to_bib(ret)
validity_hash_to_bib(ret)
ret[:keyword] = array(ret[:keyword])
ret[:license] = array(ret[:license])
ret
end

Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_bib/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonBib
VERSION = "0.6.0".freeze
VERSION = "0.7.0".freeze
end
7 changes: 2 additions & 5 deletions lib/relaton_bib/xml_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def item_data(bibitem)
extent: fetch_extent(bibitem),
accesslocation: bibitem.xpath("./accesslocation").map(&:text),
classification: fetch_classification(bibitem),
keyword: fetch_keyword(bibitem),
keyword: bibitem.xpath("keyword").map(&:text),
license: bibitem.xpath("license").map(&:text),
validity: fetch_validity(bibitem),
}
end
Expand Down Expand Up @@ -125,10 +126,6 @@ def fetch_classification(item)
end
end

def fetch_keyword(item)
item.xpath("keyword").map &:text
end

def fetch_validity(item)
vl = item.at("./validity")
return unless vl
Expand Down
3 changes: 2 additions & 1 deletion spec/examples/bib_item.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<bibitem id="ISOTC211" type="standard">
<fetched>2020-02-13</fetched>
<fetched>2020-02-16</fetched>
<title type="main" format="text/plain" language="en" script="Latn">Geographic information</title>
<title format="text/plain" language="fr" script="Latn">Information géographique</title>
<uri type="src">https://www.iso.org/standard/53798.html</uri>
Expand Down Expand Up @@ -191,6 +191,7 @@
</extent>
<accesslocation>accesslocation1</accesslocation>
<accesslocation>accesslocation2</accesslocation>
<license>License</license>
<classification type="type">value</classification>
<classification type="keyword">Keywords</classification>
<classification type="mendeley">Mendeley Tags</classification>
Expand Down
2 changes: 2 additions & 0 deletions spec/examples/bib_item.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ keyword:
- Keyword
- Key Word

license: License

validity:
begins: "2010-10-10 12:21"
ends: "2011-02-03 18:30"
Expand Down
3 changes: 2 additions & 1 deletion spec/examples/hash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ validity:
begins: 2010-10-10 12:21
ends: 2011-02-03 18:30
revision: 2011-03-04 09:00
fetched: '2020-02-13'
fetched: '2020-02-16'
keyword:
- Keyword
- Key Word
license: License
1 change: 1 addition & 0 deletions spec/relaton_bib/bibliographic_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
RelatonBib::Classification.new(type: "mendeley", value: "Mendeley Tags"),
],
keyword: ["Keyword", "Key Word"],
license: ["License"],
validity: RelatonBib::Validity.new(
begins: Time.new(2010, 10, 10, 12, 21),
ends: Time.new(2011, 2, 3, 18,30),
Expand Down

0 comments on commit 9e5b56b

Please sign in to comment.