alphabetify 0.0.4 → 1.0.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.
- checksums.yaml +4 -4
- data/lib/alphabetify.rb +26 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02f07cc8b6cc6f304ef789f4f732b5248b69a6c9
|
4
|
+
data.tar.gz: c1b89100099513adc28aec0ddbf5450f3de155a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38eed0912931ae4b76113a163d0584353b3736545927a5bed2853b138e0de01067f6f0091e53e0d62284cd14cf8a2d72928f744f5894fd78bc13ea8a5dd6c616
|
7
|
+
data.tar.gz: 0ef96b8a84d541dbb5c11488163a155aab6b40e1b24b27b8984164751035427bd41319236ac69378ddbb1d4e818177b06f72236727d7fb7fed4f85f5f21d3728
|
data/lib/alphabetify.rb
CHANGED
@@ -19,7 +19,8 @@ class Alphabetify
|
|
19
19
|
###############################################################################################################
|
20
20
|
HASH_CHARS = ('A'..'Z').to_a
|
21
21
|
|
22
|
-
def self.generate_hash
|
22
|
+
def self.generate_hash
|
23
|
+
str = get_last_hash
|
23
24
|
complete = false
|
24
25
|
new_hash = ''
|
25
26
|
str.chars.reverse.each do |ch|
|
@@ -38,11 +39,33 @@ class Alphabetify
|
|
38
39
|
if !complete
|
39
40
|
new_hash.reverse! << HASH_CHARS.first
|
40
41
|
end
|
41
|
-
new_hash.reverse
|
42
|
+
result = new_hash.reverse
|
43
|
+
set_last_hash(result)
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
#This method can be used (preferably only once, to set the initial hash)
|
48
|
+
def self.seed_hash(seed)
|
49
|
+
#Check seed against HASH_CHARS. Throw error if any characters arent allowed
|
50
|
+
raise ArgumentError.new("The seed cannot be empty.") if seed.to_s.empty?
|
51
|
+
unless seed.to_s.each_char.detect{|c| !HASH_CHARS.include?(c) }
|
52
|
+
set_last_hash(seed)
|
53
|
+
get_last_hash
|
54
|
+
else
|
55
|
+
raise ArgumentError.new("The seed can only contain characters in #{HASH_CHARS.join}.")
|
56
|
+
end
|
42
57
|
end
|
43
58
|
|
44
59
|
private
|
45
60
|
|
61
|
+
def self.get_last_hash
|
62
|
+
File.read( File.join( __dir__, 'last-hash.txt' ) )
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.set_last_hash(new_value)
|
66
|
+
File.open( File.join( __dir__, 'last-hash.txt' ), 'w+') {|f| f.write(new_value) }
|
67
|
+
end
|
68
|
+
|
46
69
|
def self.get_next_char(char)
|
47
70
|
unless char == HASH_CHARS.last
|
48
71
|
return [char.next,false]
|
@@ -61,3 +84,4 @@ class Alphabetify
|
|
61
84
|
end
|
62
85
|
|
63
86
|
end
|
87
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alphabetify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Resudek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -47,7 +47,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
47
|
requirements:
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
50
|
+
version: 2.0.0
|
51
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
57
|
rubyforge_project:
|
58
|
-
rubygems_version: 2.4.
|
58
|
+
rubygems_version: 2.4.5.1
|
59
59
|
signing_key:
|
60
60
|
specification_version: 4
|
61
61
|
summary: Create unique alphabetical hashes
|