over_h3sentence 1.1.0 → 1.2.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/over_h3sentence.rb +51 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23fbc9ecdbb10c13cd2b6c242f9dcc354303b32be0407bd4f8999bc7d8fc5ee5
4
- data.tar.gz: 21c71368742fd8c165e363c5269886dc96f332e1efbe67d77da8ec4ad81178f0
3
+ metadata.gz: 227a97d664c397a77fd99fa09f53e868fb5f93cdb8c0e465aca953f8a8307994
4
+ data.tar.gz: fde5cd03dc9c5e36fc7a24004b7b9cda1f1bc15f9801a3c516c9ba7bf2ebc589
5
5
  SHA512:
6
- metadata.gz: b707b378d2be1b6876470a32298760a17bf9b58302ff9748f8db9b618ea04c8839d23ffa57c678918399d53533ffeb624cfa2e01a41a00847af6d1e03ec3632a
7
- data.tar.gz: 7cfaf4ba3025b4e733083b6087b55aec324692553aa3a478b6643c06b5e874cd4e316334a86d9a4b9b4bbd4238ffa89a5dbe0090c42b288a680fcae7c9fb7309
6
+ metadata.gz: 70e761149c040a7bc81ffc227c2e5fc180773d98b6e18c7509c1e84fb7cc35e8f206b00f418994df243921a03d95724c2f9d490c8ee64fb7be0da17e73b0d8d1
7
+ data.tar.gz: 9c26317b9453d89ea0dad6b4a53c46e59e8af83f699634d0210bf0f11155eee0f6dc33bd0f85698d03369b021060565c0e0a9abe666daea60a0c219fa1cb8800
@@ -11,6 +11,13 @@ class OverH3sentence
11
11
  words.join('.')
12
12
  end
13
13
 
14
+ def self.hex_id(sentence)
15
+ raise ArgumentError, 'Sentence must be 3 words long' if sentence.split('.').length != 3
16
+
17
+ h3_address = form_words_to_h3(sentence.split('.'))
18
+ h3_address.to_s(16)
19
+ end
20
+
14
21
  def self.form_h3_to_words(h3_address)
15
22
  binary = h3_address.to_s(2)
16
23
 
@@ -33,4 +40,48 @@ class OverH3sentence
33
40
 
34
41
  [first_word, second_word, third_word]
35
42
  end
43
+
44
+ def self.form_words_to_h3(words)
45
+ h3_invariant_head = '10001100'
46
+ h3_invariant_tail = '111111111'
47
+
48
+ triplet_adj = []
49
+ str_value = ''
50
+
51
+ for i in 0..words.length-1 do
52
+ for j in 0..LIST_OF_WORDS.length do
53
+ if (LIST_OF_WORDS[j] === words[i])
54
+ str_value = j.to_s
55
+ end
56
+ end
57
+ length_string = str_value.length
58
+ if (length_string < 5)
59
+ for n in 0..5-length_string-1 do
60
+ str_value = "0#{str_value}"
61
+ end
62
+ end
63
+
64
+ triplet_adj.push(str_value)
65
+ end
66
+
67
+
68
+ first_trinary_code = triplet_adj[0][0] + triplet_adj[1][0] + triplet_adj[2][0]
69
+ first_integer_value = 0
70
+
71
+ COMBINATIONS_VOCAB.each_with_index do |value, index|
72
+ if (value === first_trinary_code.to_s)
73
+ first_integer_value = index
74
+ end
75
+ end
76
+ full_integer = (first_integer_value).to_s + triplet_adj[0][-4..-1].to_s + triplet_adj[1][-4..-1].to_s + triplet_adj[2][-4..-1].to_s
77
+ binary_full_integer = full_integer.to_i.to_s(2)
78
+ binary_full_integer_length = binary_full_integer.length
79
+ for i in 0..43-binary_full_integer_length-1 do
80
+ binary_full_integer = "0#{binary_full_integer}"
81
+ end
82
+
83
+ whole_binary = h3_invariant_head + binary_full_integer + h3_invariant_tail
84
+
85
+ whole_binary.to_i(2)
86
+ end
36
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: over_h3sentence
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante