over_h3sentence 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/over_h3sentence +5 -0
- data/lib/list_of_words_v1.json +1 -0
- data/lib/over_h3sentence.rb +36 -0
- metadata +60 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class OverH3sentence
|
4
|
+
LIST_OF_WORDS = JSON.parse(File.read(File.join(File.dirname(__FILE__), './list_of_words_v1.json')))
|
5
|
+
COMBINATIONS_VOCAB = ['000','001','010','011','100','101','110','111','002','012','020','021','022','102','112','120','121','122','200','201','202','210','211','212','220','221','222']
|
6
|
+
|
7
|
+
def self.sentence(hex_id)
|
8
|
+
raise ArgumentError, 'Hex id must be 15 characters long' if hex_id.length != 15
|
9
|
+
|
10
|
+
words = form_h3_to_words(hex_id.to_i(16))
|
11
|
+
words.join('.')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.form_h3_to_words(h3_address)
|
15
|
+
binary = h3_address.to_s(2)
|
16
|
+
|
17
|
+
binary_clean = binary[8..50]
|
18
|
+
integer = binary_clean.to_i(2)
|
19
|
+
str_integer = integer.to_s
|
20
|
+
integer_length = str_integer.length
|
21
|
+
if (integer_length < 13)
|
22
|
+
for i in 0..12-integer_length do
|
23
|
+
str_integer = "0#{str_integer}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
integer_first_value = str_integer[0]
|
27
|
+
first_word_idx = "#{COMBINATIONS_VOCAB[integer_first_value.to_i][0]}#{str_integer[1,4]}".to_i % 30000
|
28
|
+
first_word = LIST_OF_WORDS[first_word_idx]
|
29
|
+
second_word_idx = "#{COMBINATIONS_VOCAB[integer_first_value.to_i][1]}#{str_integer[5..8]}".to_i % 30000
|
30
|
+
second_word = LIST_OF_WORDS[second_word_idx]
|
31
|
+
third_word_idx = "#{COMBINATIONS_VOCAB[integer_first_value.to_i][2]}#{str_integer[9..-1]}".to_i % 30000
|
32
|
+
third_word = LIST_OF_WORDS[third_word_idx.to_i]
|
33
|
+
|
34
|
+
[first_word, second_word, third_word]
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: over_h3sentence
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gregorio Galante
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Generate sentence from Over land hex id (H3 address)
|
28
|
+
email: me@gregoriogalante.com
|
29
|
+
executables:
|
30
|
+
- over_h3sentence
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/over_h3sentence
|
35
|
+
- lib/list_of_words_v1.json
|
36
|
+
- lib/over_h3sentence.rb
|
37
|
+
homepage: https://rubygems.org/gems/over_h3sentence
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.5.6
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Generate sentence from Over land hex id (H3 address)
|
60
|
+
test_files: []
|