over_h3sentence 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/over_h3sentence.rb +51 -0
  3. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9ed5221f2f3528c63065ca023014b9853037e006ac0ded5a0afd2e72843d497
4
- data.tar.gz: bd7e3f2beb0cc647acf8973cb195cca098030f7fc9bb12371d3cee602ba1515b
3
+ metadata.gz: 227a97d664c397a77fd99fa09f53e868fb5f93cdb8c0e465aca953f8a8307994
4
+ data.tar.gz: fde5cd03dc9c5e36fc7a24004b7b9cda1f1bc15f9801a3c516c9ba7bf2ebc589
5
5
  SHA512:
6
- metadata.gz: b0fc43f278c61bf08efe01d68ee8bec76c6d4badc8325beb5b2ec2eb3910c06de7f24c728db1d832a2dcd7852b687e944bd466f7a74b6813867145f97ae9c0e0
7
- data.tar.gz: ee7f57117a6dc534db2ea6f3d866f0c357bebb3c26aaa81ef1e2ac2442b16250672c9a132936795e55ac356c9a920448a0b75ce12f19e44088511a29d235ac75
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.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante
@@ -34,10 +34,12 @@ files:
34
34
  - bin/over_h3sentence
35
35
  - lib/list_of_words_v1.json
36
36
  - lib/over_h3sentence.rb
37
- homepage: https://rubygems.org/gems/over_h3sentence
37
+ homepage: https://github.com/gregogalante/over_h3sentence
38
38
  licenses:
39
39
  - MIT
40
- metadata: {}
40
+ metadata:
41
+ homepage_uri: https://github.com/gregogalante/over_h3sentence
42
+ source_code_uri: https://github.com/gregogalante/over_h3sentence
41
43
  post_install_message:
42
44
  rdoc_options: []
43
45
  require_paths: