quick_short 0.0.1

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.
@@ -0,0 +1,32 @@
1
+ module QuickShort
2
+
3
+ module ShortId
4
+
5
+ AlphabetLength = QuickShort::Alphabet.length # optimization
6
+
7
+ # Encode a numeric ID
8
+ def self.encode(id)
9
+ alpha = ''
10
+ while id != 0
11
+ alpha = QuickShort::Alphabet[id % AlphabetLength].chr + alpha
12
+ id /= AlphabetLength
13
+ end
14
+ alpha
15
+ end
16
+
17
+ # Decode an ID created with encode
18
+ def self.decode(alpha)
19
+ alpha = alpha.dup; id = 0
20
+ 0.upto(alpha.length - 1) do |i|
21
+ letter = alpha[alpha.length - 1]
22
+ alphabet_index = QuickShort::Alphabet.index letter
23
+ raise ArgumentError.new("Character not in Alphabet: #{letter}") unless alphabet_index # bad character present
24
+ id += alphabet_index * (AlphabetLength ** i)
25
+ alpha.chop!
26
+ end
27
+ id
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,5 @@
1
+ module QuickShort
2
+
3
+ VERSION = '0.0.1'
4
+
5
+ end
@@ -0,0 +1,10 @@
1
+ module QuickShort
2
+
3
+ # This is the sequence of characters we use to encode the ID
4
+ # Note: We cut out vowels to avoid shortened strings from mistakenly
5
+ # forming words
6
+ Alphabet = 'bcdfghjklmnpqrstvwxyz0123456789BCDFGHJKLMNPQRSTVWXYZ'
7
+
8
+ require 'lib/quick_short/short_id.rb'
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quick_short
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - John Crepezzi
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-25 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: quick_short is a really awesome way to generate short URLs (especially for local resources)
36
+ email: john@crepezzi.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/quick_short/short_id.rb
45
+ - lib/quick_short/version.rb
46
+ - lib/quick_short.rb
47
+ has_rdoc: true
48
+ homepage: http://seejohnrun.github.com/quick_short/
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project: quick-short
77
+ rubygems_version: 1.3.7
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Rails Short URL Library - Employs Magic
81
+ test_files: []
82
+