stanford-mods 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78de4ef412a944f30348ca304d532bc275806ee4
4
- data.tar.gz: 3127f3b4e900620d2a130292733957bdb63a685a
3
+ metadata.gz: a21780e0eb52230a1237022dbe52133a6ffcfb3e
4
+ data.tar.gz: 46e8908da12e2fb68a00410a5b634d2f63752249
5
5
  SHA512:
6
- metadata.gz: 9d65a7dc751eaff5edc2238935a469c32d1c25d5e3965464e4c56c7019a3f865c4103025188a767e56fd58c01b772a6485945c07e81a6ceeff4b133e1878d4d0
7
- data.tar.gz: abf7f4068718169e8afcc61accb4d652c90b18ec8caa1eb7bf0f08740386b39dbbb14a962e00831bbb14a1b211e1eba05b18fb03e804d1ab0be887aec788b086
6
+ metadata.gz: 73883c77e8c2dde788468eafa93c55e8e9aa19f4bfd61d259439fb08592b180ebc870fe706075fb0722e8970769101ac397ec4740c31bc3a45c54a6aa19585e5
7
+ data.tar.gz: 59afb90817a8252a3e9a1d696f7d289dc1874ab3d7ad89bd9fb4cb9800ffc5a4f614e8ed72258cd50edea8fab436d6096931b18b73207688d2c943608496cc16
@@ -2,50 +2,58 @@
2
2
  require 'logger'
3
3
  require 'mods'
4
4
 
5
- # NON-SearchWorks specific wranglings of MODS cartographics metadata
6
5
  module Stanford
7
6
  module Mods
8
-
7
+ # NON-SearchWorks specific wranglings of MODS cartographics metadata
9
8
  class Record < ::Mods::Record
10
-
11
9
  def coordinates
12
10
  Array(@mods_ng_xml.subject.cartographics.coordinates).map(&:text)
13
11
  end
14
12
 
15
13
  def point_bbox
16
14
  coordinates.map do |n|
17
- matches = n.match(/^\(([^)]+)\)\.?$/)
18
- next unless matches
19
- coord_to_bbox(matches[1])
15
+ matches = n.match(/^\(?([^)]+)\)?\.?$/)
16
+
17
+ if matches
18
+ coord_to_bbox(matches[1])
19
+ else
20
+ coord_to_bbox(n)
21
+ end
20
22
  end.compact
21
23
  end
22
24
 
23
25
  private
24
26
 
25
27
  def coord_to_bbox(coord)
26
- matches = coord.match %r{(?<lat>.+--.+)\s*/\s*(?<lng>.+--.+)}
28
+ matches = coord.match %r{\A(?<lat>[EW].+--.+)\s*/\s*(?<lng>[NS].+--.+)\Z}
27
29
  return unless matches
28
30
 
29
31
  min_x, max_x = matches['lat'].split('--').map { |x| coord_to_decimal(x) }
30
32
  max_y, min_y = matches['lng'].split('--').map { |y| coord_to_decimal(y) }
31
33
 
32
- "#{min_x} #{min_y} #{max_x} #{max_y}"
34
+ "#{min_x} #{min_y} #{max_x} #{max_y}" if valid_bbox?(min_x, max_x, max_y, min_y)
33
35
  end
34
36
 
35
37
  def coord_to_decimal(point)
36
- regex = /(?<dir>[NESW])\s*(?<deg>\d+)°(?:(?<sec>\d+)ʹ)?/
38
+ regex = /(?<dir>[NESW])\s*(?<deg>\d+)°(?:(?<min>\d+)[ʹ'])?(?:(?<sec>\d+)[ʺ"])?/
37
39
  match = regex.match(point)
38
40
 
39
- return unless match
40
-
41
- dec = 0
41
+ return Float::NAN unless match
42
42
 
43
- dec += match['deg'].to_i
44
- dec += match['sec'].to_f / 60
43
+ dec = match['deg'].to_i
44
+ dec += match['min'].to_f / 60
45
+ dec += match['sec'].to_f / 60 / 60
45
46
  dec = -1 * dec if match['dir'] == 'W' || match['dir'] == 'S'
46
47
 
47
48
  dec
48
49
  end
50
+
51
+ def valid_bbox?(min_x, max_x, max_y, min_y)
52
+ range_x = -180.0..180.0
53
+ range_y = -90.0..90.0
54
+
55
+ range_x.include?(min_x) && range_x.include?(max_x) && range_y.include?(min_y) && range_y.include?(max_y)
56
+ end
49
57
  end # class Record
50
58
  end # Module Mods
51
59
  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.3.1"
4
+ VERSION = "1.3.2"
5
5
  end
6
6
  end
@@ -66,6 +66,36 @@ describe "Cartographic coordinates" do
66
66
  smods_rec.from_str(with_coords)
67
67
  expect(smods_rec.point_bbox).to eq(["-16.0 -15.0 28.0 13.0"])
68
68
  end
69
- end
70
69
 
70
+ {
71
+ %((W 123°23ʹ16ʺ--W 122°31ʹ22ʺ/N 39°23ʹ57ʺ--N 38°17ʹ53ʺ)) =>
72
+ ['-123.38777777777779 38.29805555555556 -122.52277777777778 39.399166666666666'],
73
+ %(E 10°03'00"--E 12°58'00"/N 45°00'00"--N 41°46'00") =>
74
+ ['10.05 41.766666666666666 12.966666666666667 45.0'],
75
+ %(W80°--E100°/N487°--S42°) =>
76
+ [], # N487 is out of bounds for the bounding box
77
+ %(W 650--W 100/N 700--N 550) =>
78
+ [] # missing degree character, and all coordinates are out of bounds.
79
+ }.each do |value, expected|
80
+ describe 'data mappings' do
81
+ let(:mods) do
82
+ <<-EOF
83
+ <mods xmlns="#{Mods::MODS_NS}">
84
+ <subject>
85
+ <cartographics>
86
+ <coordinates>#{value}</coordinates>
87
+ </cartographics>
88
+ </subject>
89
+ </mods>
90
+ EOF
91
+ end
92
+
93
+ let(:smods_rec) { Stanford::Mods::Record.new.from_str(mods) }
94
+
95
+ it 'maps to the right bounding box' do
96
+ expect(smods_rec.point_bbox).to eq expected
97
+ end
98
+ end
99
+ end
100
+ end
71
101
  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.3.1
4
+ version: 1.3.2
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-12-03 00:00:00.000000000 Z
12
+ date: 2015-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mods