stanford-geo 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: a9084a2315eada6391743c282970117cd111473c80987d24ad858bc6efe044c3
4
- data.tar.gz: b91d4f6689a79e01a381d52b3575a313be663309a07b7f35d9403f5c8a9265b7
3
+ metadata.gz: 2b716eafbfe765e17c06ead1a1a281766e4c4db95c3990beb5439b0cad4fc82f
4
+ data.tar.gz: 183f7882e1bbc8b5bdf4a5b488d5c1be1ba4928f404b3afbd6f939e57da6a1ea
5
5
  SHA512:
6
- metadata.gz: 22fdb6a5944c360c0d88d56b4f3dd03c266c10b804b08f7295ba6868a6c6763e02823a3ce224c1636e6ff3866e7421f2027eda7a21755b0387df673604f579ff
7
- data.tar.gz: 431f1ccd94e6df58a2c04f0071f6e7ee50f4037552f059889f760e119e28be0495ca1244499aef5e9244f5aa3f40fa11840be479bc0fc40541b65db4750873d9
6
+ metadata.gz: 9fb91ae1ea3522d1c77cc410231304cda9c58dce19778b428016a67ac1b83530c3b231360946d3bcb378a736436c5ad8c0dc657045784321d0eac2d75621fe55
7
+ data.tar.gz: c10e8f74451c59f9c603ed042197182c11da135b77b8c4f42546adb29a596262d644e333422d9e2211f7dc1361e5019b4b1ccb344a57ac6d47fac82b8967e785
data/README.md CHANGED
@@ -4,19 +4,20 @@ This gem provides some shared classes for dealing with Geo data.
4
4
 
5
5
  ## Installation
6
6
 
7
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
-
9
7
  Install the gem and add to the application's Gemfile by executing:
10
8
 
11
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
9
+ $ bundle add stanford-geo
12
10
 
13
11
  If bundler is not being used to manage dependencies, install the gem by executing:
14
12
 
15
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
13
+ $ gem install stanford-geo
16
14
 
17
15
  ## Usage
18
16
 
19
- TODO: Write usage instructions here
17
+ ```
18
+ require 'stanford/geo'
19
+ Stanford::Mods::Coordinate.new(coordinates).valid?
20
+ ```
20
21
 
21
22
  ## Development
22
23
 
@@ -10,10 +10,47 @@ module Stanford
10
10
  /^\s*(?<dir>[NESW])\s*(?<deg>\d+(?:[.]\d+)?)\s*$/
11
11
  )
12
12
 
13
- attr_reader :value
13
+ attr_reader :bounds
14
14
 
15
- def initialize(value)
16
- @value = value
15
+ # @param [String] point coordinate point in degrees notation
16
+ # @return [Float] converted value in decimal notation
17
+ def self.coord_to_decimal(point)
18
+ match = COORD_TO_DECIMAL_REGEX.match(point)
19
+ return Float::INFINITY unless match
20
+
21
+ dec = match["deg"].to_f
22
+ dec += match["min"].to_f / 60
23
+ dec += match["sec"].to_f / 60 / 60
24
+ dec = -1 * dec if match["dir"] == "W" || match["dir"] == "S"
25
+ dec
26
+ end
27
+
28
+ # @param [String] val Coordinates value
29
+ # @return [String] cleaned value (strips parens and period), or the original value
30
+ def self.cleaner_coordinate(value)
31
+ matches = value.match(/^\(?([^)]+)\)?\.?$/)
32
+ matches ? matches[1] : value
33
+ end
34
+
35
+ def self.parse_bounds(value)
36
+ matches = cleaner_coordinate(value).match %r{\A(?<lat>[EW].+-+.+)\s*/\s*(?<lng>[NS].+-+.+)\Z}
37
+ return { min_x: nil, min_y: nil, max_x: nil, max_y: nil } unless matches
38
+
39
+ min_x, max_x = matches["lat"].split(/-+/).map { |x| coord_to_decimal(x) }.minmax
40
+ min_y, max_y = matches["lng"].split(/-+/).map { |y| coord_to_decimal(y) }.minmax
41
+ { min_x: min_x, min_y: min_y, max_x: max_x, max_y: max_y }
42
+ end
43
+
44
+ def self.parse(value)
45
+ new(**parse_bounds(value))
46
+ end
47
+
48
+ def initialize(min_x:, min_y:, max_x:, max_y:)
49
+ @bounds = begin
50
+ { min_x: Float(min_x), min_y: Float(min_y), max_x: Float(max_x), max_y: Float(max_y) }
51
+ rescue TypeError, ArgumentError
52
+ {}
53
+ end
17
54
  end
18
55
 
19
56
  # @return [String] the coordinate in WKT/CQL ENVELOPE representation
@@ -42,44 +79,6 @@ module Stanford
42
79
  range_y.include?(bounds[:min_y]) &&
43
80
  range_y.include?(bounds[:max_y])
44
81
  end
45
-
46
- private
47
-
48
- def bounds
49
- @bounds ||= begin
50
- matches = cleaner_coordinate(value).match %r{\A(?<lat>[EW].+-+.+)\s*/\s*(?<lng>[NS].+-+.+)\Z}
51
- return {} unless matches
52
-
53
- min_x, max_x = matches["lat"].split(/-+/).map { |x| coord_to_decimal(x) }.minmax
54
- min_y, max_y = matches["lng"].split(/-+/).map { |y| coord_to_decimal(y) }.minmax
55
- { min_x: min_x, min_y: min_y, max_x: max_x, max_y: max_y }
56
- end
57
- end
58
-
59
- # @deprecated see GeoUtils
60
- def coord
61
- cleaner_coordinate(value)
62
- end
63
-
64
- # @param [String] val Coordinates value
65
- # @return [String] cleaned value (strips parens and period), or the original value
66
- def cleaner_coordinate(val)
67
- matches = val.match(/^\(?([^)]+)\)?\.?$/)
68
- matches ? matches[1] : val
69
- end
70
-
71
- # @param [String] point coordinate point in degrees notation
72
- # @return [Float] converted value in decimal notation
73
- def coord_to_decimal(point)
74
- match = COORD_TO_DECIMAL_REGEX.match(point)
75
- return Float::INFINITY unless match
76
-
77
- dec = match["deg"].to_f
78
- dec += match["min"].to_f / 60
79
- dec += match["sec"].to_f / 60 / 60
80
- dec = -1 * dec if match["dir"] == "W" || match["dir"] == "S"
81
- dec
82
- end
83
82
  end
84
83
  end
85
84
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Stanford
4
4
  module Geo
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stanford-geo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-08 00:00:00.000000000 Z
11
+ date: 2024-06-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  requirements: []
48
- rubygems_version: 3.5.4
48
+ rubygems_version: 3.5.10
49
49
  signing_key:
50
50
  specification_version: 4
51
51
  summary: Geo related data for Stanford Libraries