friendly_digest 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/LICENSE +26 -0
- data/Manifest +6 -0
- data/README +18 -0
- data/Rakefile +7 -0
- data/friendly_digest.gemspec +30 -0
- data/lib/friendly_digest.rb +24 -0
- metadata +78 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v1.0. Initial commit. Only supports integers.
|
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2010, Andrew Snow
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
* this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer in the
|
11
|
+
* documentation and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of the author nor the names of its
|
13
|
+
* contributors may be used to endorse or promote products derived from
|
14
|
+
* this software without specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
20
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
21
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26
|
+
POSSIBILITY OF SUCH DAMAGE.
|
data/Manifest
ADDED
data/README
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
friendly_digest: Makes passing IDs around less error prone and user-friendly
|
3
|
+
------------------------------------------------------------------------------
|
4
|
+
|
5
|
+
Avoids mistakes like 0 vs O, 1 vs L
|
6
|
+
|
7
|
+
gem install 'friendly_digest'
|
8
|
+
|
9
|
+
|
10
|
+
require 'friendly_digest'
|
11
|
+
|
12
|
+
irb> FriendlyDigest.new(12345)
|
13
|
+
=> "4AD"
|
14
|
+
|
15
|
+
irb> FriendlyDigest.decode('4ad')
|
16
|
+
=> 12345
|
17
|
+
|
18
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{friendly_digest}
|
5
|
+
s.version = "1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Andrew Snow"]
|
9
|
+
s.date = %q{2010-12-11}
|
10
|
+
s.description = %q{Ruby gem to send to convert integer IDs into easy to type strings}
|
11
|
+
s.email = %q{andrew@modulus.org}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/friendly_digest.rb"]
|
13
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "lib/friendly_digest.rb", "friendly_digest.gemspec"]
|
14
|
+
s.homepage = %q{}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Friendly_digest", "--main", "README"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{friendly_digest}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{Ruby gem to send to convert integer IDs into easy to type strings}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
class FriendlyDigest < String
|
3
|
+
class << self
|
4
|
+
def [](*p) ; new(*p) ; end
|
5
|
+
|
6
|
+
def codes
|
7
|
+
@codes ||= ['Z','2','B','T','C','9','H','Q','V','K','N','W','7','P','4','J','Y','G','E','A','D','3','F','8','M','X','6','U','R']
|
8
|
+
end
|
9
|
+
|
10
|
+
def decode(input)
|
11
|
+
input.strip.upcase.split('').inject(0) {|tot,c| (tot * codes.length) + codes.index(c) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(input)
|
16
|
+
output = input == 0 ? [self.class.codes.first] : []
|
17
|
+
while input > 0
|
18
|
+
rem = input % self.class.codes.length
|
19
|
+
input = (input - rem) / self.class.codes.length #/
|
20
|
+
output << self.class.codes[rem]
|
21
|
+
end
|
22
|
+
output.reverse.each {|c| self << c }
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: friendly_digest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
version: "1.0"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Andrew Snow
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-12-11 00:00:00 +11:00
|
17
|
+
default_executable:
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: Ruby gem to send to convert integer IDs into easy to type strings
|
21
|
+
email: andrew@modulus.org
|
22
|
+
executables: []
|
23
|
+
|
24
|
+
extensions: []
|
25
|
+
|
26
|
+
extra_rdoc_files:
|
27
|
+
- CHANGELOG
|
28
|
+
- LICENSE
|
29
|
+
- README
|
30
|
+
- lib/friendly_digest.rb
|
31
|
+
files:
|
32
|
+
- CHANGELOG
|
33
|
+
- LICENSE
|
34
|
+
- Manifest
|
35
|
+
- README
|
36
|
+
- Rakefile
|
37
|
+
- lib/friendly_digest.rb
|
38
|
+
- friendly_digest.gemspec
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: ""
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --line-numbers
|
46
|
+
- --inline-source
|
47
|
+
- --title
|
48
|
+
- Friendly_digest
|
49
|
+
- --main
|
50
|
+
- README
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 1
|
68
|
+
- 2
|
69
|
+
version: "1.2"
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project: friendly_digest
|
73
|
+
rubygems_version: 1.3.7
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Ruby gem to send to convert integer IDs into easy to type strings
|
77
|
+
test_files: []
|
78
|
+
|