new_base_60 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
@@ -0,0 +1,26 @@
1
+ === 1.0.3 / 2010-11-16
2
+
3
+ * 1 minor enhancement
4
+
5
+ * Changed named from newbase60 to new_base_60
6
+
7
+ === 1.0.2 / 2010-06-21
8
+
9
+ * 2 minor enhancement
10
+
11
+ * Code cleanup thanks to John Barnette
12
+ * Credits section added to README, props to Tantek Çelik for original idea
13
+
14
+ === 1.0.1 / 2010-06-11
15
+
16
+ * 1 minor enhancement
17
+
18
+ * Updated README to reflect changes to API
19
+ * Changed Newbase60#to_time to Newbase60#to_date
20
+
21
+ === 1.0.0 / 2010-06-11
22
+
23
+ * 1 major enhancement
24
+
25
+ * Birthday!
26
+
@@ -0,0 +1,7 @@
1
+ .autotest
2
+ CHANGELOG.rdoc
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/new_base_60.rb
7
+ test/test_new_base_60.rb
@@ -0,0 +1,49 @@
1
+ = new_base_60
2
+
3
+ * http://github.com/veganstraightedge/New_base_60
4
+
5
+ == DESCRIPTION:
6
+
7
+ Handy Conversion Sexagesimal (base 60) for Short URLs
8
+ Cuts out ambiguous characters like:
9
+ * l : lowercase l (looks like a 1 : one)
10
+ * I : capital I (looks like a 1 : one)
11
+ * O : capital O (looks like a 0 : zero)
12
+
13
+ Based on work done by Tantek Çelik : http://tantek.pbworks.com/New_base_60
14
+
15
+ == FEATURES/PROBLEMS:
16
+
17
+ * Converts Base10 (like 147124) to Base60 (like fs4)
18
+ * Converts Base60 (like fs4) to Base60 (like 147124)
19
+ * Converts Base60 (like fs4) to a Time object (Mon Oct 23 23:00:00 -0800 2372)
20
+
21
+ == SYNOPSIS:
22
+
23
+ How to use:
24
+
25
+ require "new_base_60"
26
+ n = New_base_60.new("464")# => #<New_base_60:0x1011ea468 @base_60="464">
27
+ puts n.to_i # => 14764
28
+ puts n.to_i.to_sxg # => "464"
29
+ puts n.to_date # => #<Date: 4910703/2,0,2299161>
30
+ puts n.to_date.to_s # => "2010-06-04"
31
+ puts n.to_date.to_sxg # => "464"
32
+
33
+ == INSTALL:
34
+
35
+ * sudo gem install new_base_60
36
+
37
+ == CREDITS:
38
+
39
+ * Original Idea : Tantek Çelik
40
+ * Ruby Port : Shane Becker
41
+ * Lotsa Cleanup : John Barnette
42
+
43
+ * sudo gem install new_base_60
44
+
45
+ == LICENSE:
46
+
47
+ PUBLIC DOMAIN.
48
+ Your heart is as free as the air you breathe.
49
+ The ground you stand on is liberated territory.
@@ -0,0 +1,14 @@
1
+ require "rubygems"
2
+ require "hoe"
3
+
4
+ Hoe.plugins.delete :rubyforge
5
+
6
+ Hoe.plugin :doofus, :git
7
+
8
+ Hoe.spec "new_base_60" do
9
+ developer "Shane Becker", "veganstraightedge@example.com"
10
+
11
+ self.extra_rdoc_files = Dir["*.rdoc"]
12
+ self.history_file = "CHANGELOG.rdoc"
13
+ self.readme_file = "README.rdoc"
14
+ end
@@ -0,0 +1,92 @@
1
+ require "date"
2
+ require "time"
3
+
4
+ class New_base_60
5
+ VERSION = '1.0.3'
6
+ VOCABULARY = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz"
7
+
8
+ def initialize(base_60)
9
+ @base_60 = base_60
10
+ end
11
+
12
+ def to_s
13
+ @base_60
14
+ end
15
+
16
+ # Converts into a base 10 integer.
17
+ def to_i
18
+ num = 0
19
+
20
+ @base_60.bytes do |char|
21
+ case char
22
+ when 48..57 then char -= 48
23
+ when 65..72 then char -= 55
24
+ when 73, 108 then char = 1 # typo capital I, lowercase l to 1
25
+ when 74..78 then char -= 56
26
+ when 79 then char = 0 # error correct typo capital O to 0
27
+ when 80..90 then char -= 57
28
+ when 95 then char = 34
29
+ when 97..107 then char -= 62
30
+ when 109..122 then char -= 63
31
+ else char = 0 # treat all other noise as 0
32
+ end
33
+
34
+ num = 60 * num + char
35
+ end
36
+
37
+ num
38
+ end
39
+
40
+ # Converts into a Date.
41
+ def to_date
42
+ # HACK this is smelly
43
+ # days since epoch * seconds * minutes * hours + timezone
44
+ time = Time.at(New_base_60.new(@base_60).to_i *
45
+ 60 * 60 * 24 + Time.now.gmtoff.abs)
46
+
47
+ Date.parse(time.strftime("%Y/%m/%d"))
48
+ end
49
+ end
50
+
51
+ class Integer
52
+ # Converts a base 10 integer into a New_base_60 string.
53
+ def to_sxg
54
+ return "" if zero?
55
+
56
+ num = self
57
+ sxg = ""
58
+
59
+ while num > 0 do
60
+ mod = num % 60
61
+ sxg = "#{New_base_60::VOCABULARY[mod,1]}#{sxg}"
62
+ num = (num - mod) / 60
63
+ end
64
+
65
+ sxg
66
+ end
67
+
68
+ # Converts a base 10 integer into a New_base_60 string,
69
+ # padding with leading zeroes.
70
+ def to_sxgf(padding)
71
+ num = self
72
+
73
+ str = num.to_sxg
74
+
75
+ padding = 1 if padding.nil?
76
+ padding -= str.length
77
+
78
+ while padding > 0
79
+ str = "0#{str}"
80
+ padding -= 1
81
+ end
82
+
83
+ str
84
+ end
85
+ end
86
+
87
+ class Date
88
+ # Converts into a New_base_60 string.
89
+ def to_sxg
90
+ (self - Date.parse("1970/01/01")).to_i.to_sxg
91
+ end
92
+ end
@@ -0,0 +1,29 @@
1
+ require "test/unit"
2
+ require "new_base_60"
3
+
4
+ class TestNew_base_60 < Test::Unit::TestCase
5
+ def test_base60_to_base10
6
+ assert_equal New_base_60.new("464").to_i, 14764
7
+ assert_not_equal New_base_60.new("464").to_i, 12345
8
+ end
9
+
10
+ def test_base60_to_date
11
+ assert_equal New_base_60.new("464").to_date, Date.parse("2010/06/04")
12
+ assert_not_equal New_base_60.new("464").to_date, Date.parse("2010/06/05")
13
+ end
14
+
15
+ def test_date_to_base60
16
+ assert_equal Date.parse("2010/06/04").to_sxg, New_base_60.new("464").to_s
17
+ assert_not_equal Date.parse("2010/06/05").to_sxg, New_base_60.new("464")
18
+ end
19
+
20
+ def test_base10_to_base60
21
+ assert_equal 14764.to_sxg, "464"
22
+ assert_not_equal 12345.to_sxg, "464"
23
+ end
24
+
25
+ def test_base10_to_base60_with_leading_zeroes
26
+ assert_equal 14764.to_sxgf(9), "000000464"
27
+ assert_not_equal 12345.to_sxgf(9), "000000464"
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: new_base_60
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 3
10
+ version: 1.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Shane Becker
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-16 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: hoe
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 21
30
+ segments:
31
+ - 2
32
+ - 6
33
+ - 1
34
+ version: 2.6.1
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: "Handy Conversion Sexagesimal (base 60) for Short URLs\n\
38
+ Cuts out ambiguous characters like:\n\
39
+ * l : lowercase l (looks like a 1 : one)\n\
40
+ * I : capital I (looks like a 1 : one)\n\
41
+ * O : capital O (looks like a 0 : zero)\n\n\
42
+ Based on work done by Tantek \xC3\x87elik : http://tantek.pbworks.com/New_base_60"
43
+ email:
44
+ - veganstraightedge@example.com
45
+ executables: []
46
+
47
+ extensions: []
48
+
49
+ extra_rdoc_files:
50
+ - Manifest.txt
51
+ - CHANGELOG.rdoc
52
+ - README.rdoc
53
+ files:
54
+ - .autotest
55
+ - CHANGELOG.rdoc
56
+ - Manifest.txt
57
+ - README.rdoc
58
+ - Rakefile
59
+ - lib/new_base_60.rb
60
+ - test/test_new_base_60.rb
61
+ has_rdoc: true
62
+ homepage: http://github.com/veganstraightedge/New_base_60
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --main
68
+ - README.rdoc
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project: new_base_60
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: "Handy Conversion Sexagesimal (base 60) for Short URLs Cuts out ambiguous characters like: * l : lowercase l (looks like a 1 : one) * I : capital I (looks like a 1 : one) * O : capital O (looks like a 0 : zero) Based on work done by Tantek \xC3\x87elik : http://tantek.pbworks.com/New_base_60"
96
+ test_files:
97
+ - test/test_new_base_60.rb