maiden 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9acfaf45e5e82aed00079683f07d19a5b43864710cca57e15ef00e19ba9c0ac1
4
+ data.tar.gz: f479c46b68cabb91817b4e2572c5893f75de93a6d708de80c280e29a09f2f8b4
5
+ SHA512:
6
+ metadata.gz: aa476a47ba90f5ef8d3588e01b31962fc070bb76289152b499a4920ae885b70fd3ec5637bb4773cb3b4fa07fbe0a5cd1a856b443ec7f55ae0ef3fbc352876503
7
+ data.tar.gz: eb88ed4d15490fe00efe5ebac97fad0134e9d9db7ade58d66e95b15b7d6f1ba11743d7c553479d227a25be70f80baaed5e0c6f9980ddc63c17485ff35901cb20
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-02-18
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Maiden
2
+ A simple republishing of a gem to calculate maidenhead gridsquares by gps coordinates.
3
+
4
+ ## Installation
5
+
6
+ ### bundle
7
+ ```
8
+ bundle add maiden
9
+ ```
10
+
11
+ ### gem
12
+ ```
13
+ gem install maiden
14
+ ```
15
+
16
+ ### build
17
+ ```
18
+ gem build maiden.gemspec
19
+ ```
20
+
21
+ ## Usage
22
+ ```
23
+ require 'maiden'
24
+ ```
25
+
26
+ ### to grid
27
+ ```
28
+ gridsquare = GRID.to_grid(latitude, longitude)
29
+ ```
30
+
31
+ ### to gps
32
+ ```
33
+ latitude, longitude = GRID.to_gps(gridsquare)
34
+ ```
35
+
36
+ ### gridsquares
37
+ ```
38
+ GRID.keys
39
+ ```
40
+
41
+ ### gridsquare stack
42
+ ```
43
+ GRID[gridsquare]
44
+ ```
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Maiden
4
+ VERSION = "0.1.0"
5
+ end
data/lib/maiden.rb ADDED
@@ -0,0 +1,166 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "maiden/version"
4
+
5
+ module Maidenhead
6
+ class Error < StandardError; end
7
+
8
+ def self.valid_maidenhead?(location)
9
+ return false unless location.is_a?String
10
+ return false unless location.length >= 2
11
+ return false unless (location.length % 2) == 0
12
+
13
+ length = location.length / 2
14
+ length.times do |counter|
15
+ grid = location[counter * 2, 2]
16
+ if (counter == 0)
17
+ return false unless grid =~ /[a-rA-R]{2}/
18
+ elsif (counter % 2) == 0
19
+ return false unless grid =~ /[a-xA-X]{2}/
20
+ else
21
+ return false unless grid =~ /[0-9]{2}/
22
+ end
23
+ end
24
+ true
25
+ end
26
+ def self.to_latlon(location);
27
+ maidenhead = Maidenhead.new; maidenhead.locator = location; return [ maidenhead.lat, maidenhead.lon ]
28
+ end
29
+ def locator=(location)
30
+ unless Maidenhead.valid_maidenhead?(location)
31
+ raise ArgumentError.new("Location is not a valid Maidenhead Locator System string")
32
+ end
33
+ @locator = location
34
+ @lat = -90.0
35
+ @lon = -180.0
36
+ pad_locator
37
+ convert_part_to_latlon(0, 1)
38
+ convert_part_to_latlon(1, 10)
39
+ convert_part_to_latlon(2, 10 * 24)
40
+ convert_part_to_latlon(3, 10 * 24 * 10)
41
+ convert_part_to_latlon(4, 10 * 24 * 10 * 24)
42
+ end
43
+ def self.to_maidenhead(lat, lon, precision = 5)
44
+ maidenhead = Maidenhead.new
45
+ maidenhead.lat = lat
46
+ maidenhead.lon = lon
47
+ maidenhead.precision = precision
48
+ maidenhead.locator
49
+ end
50
+ def lat=(pos); @lat = range_check("lat", 90.0, pos); end
51
+ def lat; @lat.round(6); end
52
+ def lon=(pos); @lon = range_check("lon", 180.0, pos); end
53
+ def lon; @lon.round(6); end
54
+ def precision=(value); @precision = value; end
55
+ def precision; @precision; end
56
+ def locator
57
+ @locator = ''
58
+ @lat_tmp = @lat + 90.0
59
+ @lon_tmp = @lon + 180.0
60
+ @precision_tmp = @precision
61
+ calculate_field
62
+ calculate_values
63
+ @locator
64
+ end
65
+
66
+ private
67
+
68
+ def pad_locator
69
+ length = @locator.length / 2
70
+ while (length < 5)
71
+ if (length % 2) == 1
72
+ @locator += '55'
73
+ else
74
+ @locator += 'LL'
75
+ end
76
+ length = @locator.length / 2
77
+ end
78
+ end
79
+ def convert_part_to_latlon(counter, divisor)
80
+ grid_lon = @locator[counter * 2, 1]
81
+ grid_lat = @locator[counter * 2 + 1, 1]
82
+ @lat += l2n(grid_lat) * 10.0 / divisor
83
+ @lon += l2n(grid_lon) * 20.0 / divisor
84
+ end
85
+ def calculate_field
86
+ @lat_tmp = (@lat_tmp / 10) + 0.0000001
87
+ @lon_tmp = (@lon_tmp / 20) + 0.0000001
88
+ @locator += n2l(@lon_tmp.floor).upcase + n2l(@lat_tmp.floor).upcase
89
+ @precision_tmp -= 1
90
+ end
91
+ def compute_locator(counter, divisor)
92
+ @lat_tmp = (@lat_tmp - @lat_tmp.floor) * divisor
93
+ @lon_tmp = (@lon_tmp - @lon_tmp.floor) * divisor
94
+ if (counter % 2) == 0
95
+ @locator += "#{@lon_tmp.floor}#{@lat_tmp.floor}"
96
+ else
97
+ @locator += n2l(@lon_tmp.floor) + n2l(@lat_tmp.floor)
98
+ end
99
+ end
100
+ def calculate_values
101
+ @precision_tmp.times do |counter|
102
+ if (counter % 2) == 0
103
+ compute_locator(counter, 10)
104
+ else
105
+ compute_locator(counter, 24)
106
+ end
107
+ end
108
+ end
109
+ def l2n(letter)
110
+ if letter =~ /[0-9]+/
111
+ letter.to_i
112
+ else
113
+ letter.downcase.ord - 97
114
+ end
115
+ end
116
+ def n2l(number)
117
+ (number + 97).chr
118
+ end
119
+ def range_check(target, range, pos)
120
+ pos = pos.to_f
121
+ if pos < -range or pos > range
122
+ raise ArgumentError.new("#{target} must be between -#{range} and +#{range}")
123
+ end
124
+ pos
125
+ end
126
+ end
127
+
128
+ module GRID
129
+ @@GRID_SIZE = 4
130
+
131
+ ##
132
+ # gridsquare size
133
+ def self.precision= p
134
+ @@GRID_SIZE = p.to_i
135
+ end
136
+
137
+ @@G = Hash.new { |h,k| h[k] = [] }
138
+
139
+ ##
140
+ # known place stack
141
+ def self.[] k
142
+ @@G[k]
143
+ end
144
+
145
+ ##
146
+ # known grid places
147
+ def self.keys
148
+ @@G.keys
149
+ end
150
+
151
+ ##
152
+ # convert latitude / longitude to gridsquare
153
+ def self.to_grid lat,lon
154
+ g = Maidenhead.to_maidenhead(lat,lon,@@GRID_SIZE)
155
+ @@G[g]
156
+ return g
157
+ end
158
+
159
+ ##
160
+ # convert gridsquare to latitude / longitude
161
+ def self.to_gps g
162
+ @@G[g]
163
+ return Maidenhead.to_latlon(g)
164
+ end
165
+ end
166
+
data/maiden.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/maiden/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "maiden"
7
+ spec.version = Maiden::VERSION
8
+ spec.authors = ["Erik Olson"]
9
+ spec.email = ["xorgnak@gmail.com"]
10
+
11
+ spec.summary = "gps / maidenhead converter"
12
+ spec.description = "A simple republishing of a gps / maidenhead gridsquare converter with a few additions."
13
+ spec.homepage = "https://github.com/xorgnak/maiden"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (File.expand_path(f) == __FILE__) ||
26
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
data/sig/maiden.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Maiden
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maiden
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Erik Olson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-02-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple republishing of a gps / maidenhead gridsquare converter with
14
+ a few additions.
15
+ email:
16
+ - xorgnak@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - CODE_OF_CONDUCT.md
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/maiden.rb
27
+ - lib/maiden/version.rb
28
+ - maiden.gemspec
29
+ - sig/maiden.rbs
30
+ homepage: https://github.com/xorgnak/maiden
31
+ licenses:
32
+ - MIT
33
+ metadata:
34
+ homepage_uri: https://github.com/xorgnak/maiden
35
+ source_code_uri: https://github.com/xorgnak/maiden
36
+ changelog_uri: https://github.com/xorgnak/maiden
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.6.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.3.15
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: gps / maidenhead converter
56
+ test_files: []