alphabetify 0.0.2

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 +7 -0
  2. data/lib/alphabetify.rb +63 -0
  3. metadata +49 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f945579ca579d011d6db680716a94ce28724e7d0
4
+ data.tar.gz: 5f0b9186f00f6d71f92492da302b4fc724c2fc6c
5
+ SHA512:
6
+ metadata.gz: 6fc8d04bd54edbea30d623bc8161fca935490c81ed56cc04b14b4a2f51c4b10f05b5509cc5796bf05143698352b4fc566f6c91bd7c785649d1f20d420f3f1d5b
7
+ data.tar.gz: e7985f20ac9ebbdd21b1880eb4e95ab443c715adcc22e0ace5adbc25b663cfc07b1f09743ec51aab36bb947f40e1251e3c73d194c38cc311912f63b5b6647af5
@@ -0,0 +1,63 @@
1
+ class Alphabetify
2
+ ###############################################################################################################
3
+ #
4
+ # Alphabetify.rb
5
+ # Generates sequential alphabetic hashes
6
+ #
7
+ # Author: Todd Resudek - toddresudek@gmail.com | github: sprsmpl
8
+ #
9
+ # Description:
10
+ # Taking an existing alphabetic hash (of any length), will return the next hash in sequence.
11
+ # If all characters in hash are rolled over, will append a new char (increase the length by 1.)
12
+ # eg. 'ZZZZ' -> 'AAAAA'
13
+ # eg. 'AAAZ' -> 'AABA'
14
+ #
15
+ # Seed the first hash - whatever length you'd like to start with - to begin.
16
+ #
17
+ # Usage: Alphabetify.generate_hash('THELASTHASHUSED')
18
+ #
19
+ ###############################################################################################################
20
+ HASH_CHARS = ('A'..'Z').to_a
21
+
22
+ def self.generate_hash(str)
23
+ complete = false
24
+ new_hash = ''
25
+ str.chars.reverse.each do |ch|
26
+ #check this char for a rollover, if it does not need a rollver, exit
27
+ unless complete
28
+ #replace this char with the next char
29
+ next_char, rollover = get_next_char(ch)
30
+ new_hash << next_char
31
+ else
32
+ #keep this char
33
+ new_hash << ch
34
+ end
35
+ complete = true unless rollover
36
+ end
37
+ #need to add another character to the end if all letters rollover
38
+ if !complete
39
+ new_hash.reverse! << HASH_CHARS.first
40
+ end
41
+ new_hash.reverse
42
+ end
43
+
44
+ private
45
+
46
+ def self.get_next_char(char)
47
+ unless char == HASH_CHARS.last
48
+ return [char.next,false]
49
+ else
50
+ return [HASH_CHARS.first,true]
51
+ end
52
+ end
53
+
54
+ def self.leading_chars(current_hash)
55
+ last_char = current_hash.slice!(-1)
56
+ [current_hash,last_char]
57
+ end
58
+
59
+ def self.rollover
60
+ new_last_char, needs_rollover = next_char(last_char)
61
+ end
62
+
63
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alphabetify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Todd Resudek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ Taking an existing alphabetic hash (of any length), will return the next hash in sequence.
15
+ If all characters in hash are rolled over, will append a new char (increase the length by 1.)
16
+ eg. 'ZZZZ' -> 'AAAAA'
17
+ eg. 'AAAZ' -> 'AABA'
18
+ email: toddresudek@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - lib/alphabetify.rb
24
+ homepage: http://rubygems.org/gems/alphabetify
25
+ licenses:
26
+ - Apache-2.0
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.4.4
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Create unique alphabetical hashes
48
+ test_files: []
49
+ has_rdoc: