stanford-mods 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dec8a7a5501522cd7e061ee8c78ad8e9155f09ee
4
- data.tar.gz: 279acc503c49653d0edf63d86909fd7b3679efcc
3
+ metadata.gz: ad8829d81dcdd467e55484dbcad16b10ad129399
4
+ data.tar.gz: cdd05ca0ef149eb382efca02cb5b0a33e8656dd2
5
5
  SHA512:
6
- metadata.gz: 7a2239d5219fffa8346568392897d2561f7a0c68307329fa4bdbe72dc5ad5d3f24b9aeb3b3fbc4b1085d26fdb19a0eedadd00c439aa93c1313a3726d3b216a18
7
- data.tar.gz: b03a84ad3ae27ebd0b6222959afc534f2468169f1262659d74645107339b9bb21b6168a55c7252b032f000edb4b3c3e8862983adaf5c4475143c39b08899ea62
6
+ metadata.gz: 0afd49e19a7585bb2bc07b9409479aab2d458cb502d38a3aa356326cbc1bebcb5e7beac8ee0d075307274124826802ff8c6af97f4c7aa2cc8e75a1e349419bb4
7
+ data.tar.gz: 1eb35fb09de5c39ad6631dc5f8e2676d7aff58b83a10e170035cae7063d6a42432f0bd64a7b81c33392ab3ab3dae2579fea2bb1dd5f34148379c1c8e76686c32
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  script: rake
3
3
  rvm:
4
- - ruby-head
5
4
  - 2.2.3 # spotlight
6
5
  - 2.2.0
7
6
  - 2.1.5
@@ -9,9 +8,12 @@ rvm:
9
8
  - 1.9.3 # argo, FRDA
10
9
  # we used to use jruby for merged DOR + MARC records, but no more ...
11
10
  - jruby-head
11
+ # we also test against ruby-head, which may be unstable.
12
+ - ruby-head
12
13
  matrix:
13
14
  allow_failures:
14
15
  - rvm: jruby-head
16
+ - rvm: ruby-head
15
17
 
16
18
  notifications: false
17
19
  sudo: false
data/lib/stanford-mods.rb CHANGED
@@ -3,6 +3,7 @@ require 'mods'
3
3
  require 'stanford-mods/name'
4
4
  require 'stanford-mods/searchworks'
5
5
  require 'stanford-mods/physical_location'
6
+ require 'stanford-mods/geo_spatial'
6
7
 
7
8
  # Stanford specific wranglings of MODS metadata as an extension of the Mods::Record object
8
9
  module Stanford
@@ -0,0 +1,46 @@
1
+ # encoding: UTF-8
2
+ require 'logger'
3
+ require 'mods'
4
+
5
+ # NON-SearchWorks specific wranglings of MODS cartographics metadata
6
+ module Stanford
7
+ module Mods
8
+
9
+ class Record < ::Mods::Record
10
+
11
+ def coordinates
12
+ Array(@mods_ng_xml.subject.cartographics.coordinates).map(&:text)
13
+ end
14
+
15
+ def point_bbox
16
+ coordinates.map do |n|
17
+ matches = n.match(/^\(([^)]+)\)\.?$/)
18
+ next unless matches
19
+ coord_to_bbox(matches[1])
20
+ end.compact
21
+ end
22
+
23
+ private
24
+
25
+ def coord_to_bbox(coord)
26
+ lng, lat = coord.split('/')
27
+
28
+ min_x, max_x = lng.split('--').map { |x| coord_to_decimal(x) }
29
+ max_y, min_y = lat.split('--').map { |y| coord_to_decimal(y) }
30
+ "#{min_x} #{min_y} #{max_x} #{max_y}"
31
+ end
32
+
33
+ def coord_to_decimal(point)
34
+ regex = /(?<dir>[NESW])\s*(?<deg>\d+)°(?:(?<sec>\d+)ʹ)?/
35
+ match = regex.match(point)
36
+ dec = 0
37
+
38
+ dec += match['deg'].to_i
39
+ dec += match['sec'].to_f / 60
40
+ dec = -1 * dec if match['dir'] == 'W' || match['dir'] == 'S'
41
+
42
+ dec
43
+ end
44
+ end # class Record
45
+ end # Module Mods
46
+ end # Module Stanford
@@ -45,22 +45,16 @@ module Stanford
45
45
  results
46
46
  end
47
47
 
48
- COLLECTOR_ROLE_URI = 'http://id.loc.gov/vocabulary/relators/col'
49
-
50
48
  # @return Array of Strings, each containing the computed display value of a personal name
51
49
  # except for the collector role (see mods gem nom_terminology for display value algorithm)
52
50
  # FIXME: this is broken if there are multiple role codes and some of them are not marcrelator
53
51
  def non_collector_person_authors
54
52
  result = []
55
53
  @mods_ng_xml.personal_name.map do |n|
56
- unless n.role.size == 0
57
- n.role.each { |r|
58
- unless (r.authority.include?('marcrelator') && r.value.include?('Collector')) ||
59
- r.roleTerm.valueURI.first == COLLECTOR_ROLE_URI
60
- result << n.display_value_w_date
61
- end
62
- }
63
- end
54
+ next if n.role.size.zero?
55
+ n.role.each { |r|
56
+ result << n.display_value_w_date unless includes_marc_relator_collector_role?(r)
57
+ }
64
58
  end
65
59
  result unless result.empty?
66
60
  end
@@ -70,18 +64,23 @@ module Stanford
70
64
  def collectors_w_dates
71
65
  result = []
72
66
  @mods_ng_xml.personal_name.each do |n|
73
- unless n.role.size == 0
74
- n.role.each { |r|
75
- if (r.authority.include?('marcrelator') && r.value.include?('Collector')) ||
76
- r.roleTerm.valueURI.first == COLLECTOR_ROLE_URI
77
- result << n.display_value_w_date
78
- end
79
- }
80
- end
67
+ next if n.role.size.zero?
68
+ n.role.each { |r|
69
+ result << n.display_value_w_date if includes_marc_relator_collector_role?(r)
70
+ }
81
71
  end
82
72
  result unless result.empty?
83
73
  end
84
74
 
75
+ COLLECTOR_ROLE_URI = 'http://id.loc.gov/vocabulary/relators/col'
76
+
77
+ # @param Nokogiri::XML::Node role_node the role node from a parent name node
78
+ # @return true if there is a MARC relator collector role assigned
79
+ def includes_marc_relator_collector_role?(role_node)
80
+ (role_node.authority.include?('marcrelator') && role_node.value.include?('Collector')) ||
81
+ role_node.roleTerm.valueURI.first == COLLECTOR_ROLE_URI
82
+ end
83
+
85
84
  end # class Record
86
85
  end # Module Mods
87
86
  end # Module Stanford
@@ -1,6 +1,6 @@
1
1
  module Stanford
2
2
  module Mods
3
3
  # this is the Ruby Gem version
4
- VERSION = "1.2.1"
4
+ VERSION = "1.3.0"
5
5
  end
6
6
  end
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe "Cartographic coordinates" do
5
+
6
+ let(:smods_rec) { Stanford::Mods::Record.new }
7
+ let(:no_coord) do
8
+ <<-EOF
9
+ <mods xmlns="#{Mods::MODS_NS}">
10
+ <subject>
11
+ <cartographics>
12
+ <scale>Scale 1:500,000</scale>
13
+ <coordinates></coordinates>
14
+ </cartographics>
15
+ </subject>
16
+ </mods>
17
+ EOF
18
+ end
19
+ let(:with_coords) do
20
+ <<-EOF
21
+ <mods xmlns="#{Mods::MODS_NS}">
22
+ <subject>
23
+ <cartographics>
24
+ <scale>Scale 1:500,000</scale>
25
+ <coordinates>(W16°--E28°/N13°--S15°).</coordinates>
26
+ </cartographics>
27
+ </subject>
28
+ </mods>
29
+ EOF
30
+ end
31
+
32
+ context "coordinates" do
33
+ it "returns empty array if no coordinates in the mods" do
34
+ smods_rec.from_str(no_coord)
35
+ expect(smods_rec.coordinates).to eq([""])
36
+ end
37
+ it "returns decimal representation of latitude and longitude" do
38
+ smods_rec.from_str(with_coords)
39
+ expect(smods_rec.coordinates).to eq(["(W16°--E28°/N13°--S15°)."])
40
+ end
41
+ end
42
+
43
+ context "point_bbox" do
44
+ it "returns empty array if no coordinates in the mods" do
45
+ smods_rec.from_str(no_coord)
46
+ expect(smods_rec.point_bbox).to eq([])
47
+ end
48
+ it "returns decimal representation of latitude and longitude" do
49
+ smods_rec.from_str(with_coords)
50
+ expect(smods_rec.point_bbox).to eq(["-16.0 -15.0 28.0 13.0"])
51
+ end
52
+ end
53
+
54
+ end # describe Cartographic coordinates
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stanford-mods
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naomi Dushay
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-19 00:00:00.000000000 Z
12
+ date: 2015-11-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mods
@@ -106,11 +106,13 @@ files:
106
106
  - Rakefile
107
107
  - config/mappings_hash.rb
108
108
  - lib/stanford-mods.rb
109
+ - lib/stanford-mods/geo_spatial.rb
109
110
  - lib/stanford-mods/name.rb
110
111
  - lib/stanford-mods/physical_location.rb
111
112
  - lib/stanford-mods/searchworks.rb
112
113
  - lib/stanford-mods/searchworks_languages.rb
113
114
  - lib/stanford-mods/version.rb
115
+ - spec/geo_spatial_spec.rb
114
116
  - spec/name_spec.rb
115
117
  - spec/physical_location_spec.rb
116
118
  - spec/searchworks_basic_spec.rb
@@ -146,6 +148,7 @@ signing_key:
146
148
  specification_version: 4
147
149
  summary: Stanford specific wrangling of MODS metadata
148
150
  test_files:
151
+ - spec/geo_spatial_spec.rb
149
152
  - spec/name_spec.rb
150
153
  - spec/physical_location_spec.rb
151
154
  - spec/searchworks_basic_spec.rb