new_base_60 1.0.4 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ === 1.1 / 2013-01-10
2
+
3
+ * 1 minor enhancement
4
+
5
+ * Added command line script `sxg_to_dec` and `dec_to_sxg` for converting on the command line by Aaron Parecki (@aaronpk)
6
+
1
7
  === 1.0.4 / 2011-02-15
2
8
 
3
9
  * 1 minor enhancement
@@ -14,8 +20,8 @@
14
20
 
15
21
  * 2 minor enhancement
16
22
 
17
- * Code cleanup thanks to John Barnette
18
- * Credits section added to README, props to Tantek Çelik for original idea
23
+ * Code cleanup thanks to John Barnette (@jbarnette)
24
+ * Credits section added to README, props to Tantek Çelik (@tantek) for original idea
19
25
 
20
26
  === 1.0.1 / 2010-06-11
21
27
 
@@ -4,4 +4,6 @@ Manifest.txt
4
4
  README.rdoc
5
5
  Rakefile
6
6
  lib/new_base_60.rb
7
+ bin/dec_to_sxg
8
+ bin/sxg_to_dec
7
9
  test/test_new_base_60.rb
@@ -15,7 +15,7 @@ Based on work done by Tantek Çelik : http://tantek.pbworks.com/New_base_60
15
15
  == FEATURES/PROBLEMS:
16
16
 
17
17
  * Converts Base10 (like 147124) to Base60 (like fs4)
18
- * Converts Base60 (like fs4) to Base60 (like 147124)
18
+ * Converts Base60 (like fs4) to Base10 (like 147124)
19
19
  * Converts Base60 (like fs4) to a Time object (Mon Oct 23 23:00:00 -0800 2372)
20
20
 
21
21
  == SYNOPSIS:
@@ -30,15 +30,28 @@ How to use:
30
30
  puts n.to_date.to_s # => "2010-06-04"
31
31
  puts n.to_date.to_sxg # => "464"
32
32
 
33
+ Or, on the command line:
34
+
35
+ $ dec_to_sxg 115727
36
+ Y8n
37
+ $ sxg_to_dec Y8n
38
+ 115727
39
+
40
+ If you want a shortcut, add this to your .bash_profile:
41
+
42
+ alias sd="sxg_to_dec"
43
+ alias ds="dec_to_sxg"
44
+
33
45
  == INSTALL:
34
46
 
35
47
  * sudo gem install new_base_60
36
48
 
37
49
  == CREDITS:
38
50
 
39
- * Original Idea : Tantek Çelik
40
- * Ruby Port : Shane Becker
41
- * Lotsa Cleanup : John Barnette
51
+ * Original Idea : Tantek Çelik (@tantek)
52
+ * Ruby Port : Shane Becker (@veganstraightedge)
53
+ * Lotsa Cleanup : John Barnette (@jbarnette)
54
+ * Command Line Scripts : Aaron Parecki (@aaronpk)
42
55
 
43
56
  == LICENSE:
44
57
 
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'new_base_60'
4
+ puts ARGV[0].to_i.to_sxg
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'new_base_60'
4
+ n = NewBase60.new(ARGV[0])
5
+ puts n.to_i
@@ -2,7 +2,7 @@ require "date"
2
2
  require "time"
3
3
 
4
4
  class NewBase60
5
- VERSION = '1.0.4'
5
+ VERSION = '1.1'
6
6
  VOCABULARY = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz"
7
7
 
8
8
  def initialize(base_60)
@@ -39,12 +39,7 @@ class NewBase60
39
39
 
40
40
  # Converts into a Date.
41
41
  def to_date
42
- # HACK this is smelly
43
- # days since epoch * seconds * minutes * hours + timezone
44
- time = Time.at(NewBase60.new(@base_60).to_i *
45
- 60 * 60 * 24 + Time.now.gmtoff.abs)
46
-
47
- Date.parse(time.strftime("%Y/%m/%d"))
42
+ Time.at(to_i * 60 * 60 * 24).utc.to_date
48
43
  end
49
44
  end
50
45
 
@@ -67,20 +62,12 @@ class Integer
67
62
 
68
63
  # Converts a base 10 integer into a NewBase60 string,
69
64
  # padding with leading zeroes.
70
- def to_sxgf(padding)
71
- num = self
72
-
73
- str = num.to_sxg
65
+ def to_sxgf(padding=1)
66
+ str = to_sxg
74
67
 
75
- padding = 1 if padding.nil?
76
68
  padding -= str.length
77
69
 
78
- while padding > 0
79
- str = "0#{str}"
80
- padding -= 1
81
- end
82
-
83
- str
70
+ padding.times.map { "0" }.join + str
84
71
  end
85
72
  end
86
73
 
@@ -1,29 +1,34 @@
1
- require "test/unit"
2
- require "new_base_60"
1
+ require 'minitest/autorun'
2
+ require 'new_base_60'
3
3
 
4
- class TestNewBase60 < Test::Unit::TestCase
4
+ class TestCase < MiniTest::Spec
5
5
  def test_base60_to_base10
6
- assert_equal NewBase60.new("464").to_i, 14764
7
- assert_not_equal NewBase60.new("464").to_i, 12345
6
+ assert NewBase60.new("464").to_i == 14764
7
+ refute NewBase60.new("464").to_i == 12345
8
8
  end
9
9
 
10
10
  def test_base60_to_date
11
- assert_equal NewBase60.new("464").to_date, Date.parse("2010/06/04")
12
- assert_not_equal NewBase60.new("464").to_date, Date.parse("2010/06/05")
11
+ assert NewBase60.new("").to_date == Date.parse("1970/01/01")
12
+ assert NewBase60.new("4JG").to_date == Date.parse("2012/06/05")
13
+ assert NewBase60.new("464").to_date == Date.parse("2010/06/04")
14
+ refute NewBase60.new("464").to_date == Date.parse("2010/06/05")
13
15
  end
14
16
 
15
17
  def test_date_to_base60
16
- assert_equal Date.parse("2010/06/04").to_sxg, NewBase60.new("464").to_s
17
- assert_not_equal Date.parse("2010/06/05").to_sxg, NewBase60.new("464")
18
+ assert Date.parse("2010/06/04").to_sxg == NewBase60.new("464").to_s
19
+ refute Date.parse("2010/06/05").to_sxg == NewBase60.new("464")
18
20
  end
19
21
 
20
22
  def test_base10_to_base60
21
- assert_equal 14764.to_sxg, "464"
22
- assert_not_equal 12345.to_sxg, "464"
23
+ assert 14764.to_sxg == "464"
24
+ refute 12345.to_sxg == "464"
23
25
  end
24
26
 
25
27
  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
+ assert 14764.to_sxgf(1) == "464"
29
+ assert 14764.to_sxgf(5) == "00464"
30
+ assert 14764.to_sxgf() == "464"
31
+ assert 14764.to_sxgf(9) == "000000464"
32
+ refute 12345.to_sxgf(9) == "000000464"
28
33
  end
29
34
  end
metadata CHANGED
@@ -1,98 +1,109 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: new_base_60
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.1'
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 4
10
- version: 1.0.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Shane Becker
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-02-15 00:00:00 -08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: hoe
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
22
+ type: :development
23
23
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.10'
30
+ - !ruby/object:Gem::Dependency
31
+ name: hoe
32
+ requirement: !ruby/object:Gem::Requirement
25
33
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 41
30
- segments:
31
- - 2
32
- - 9
33
- - 1
34
- version: 2.9.1
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.4'
35
38
  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: []
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.4'
46
+ description: ! 'Handy Conversion Sexagesimal (base 60) for Short URLs
46
47
 
47
- extensions: []
48
+ Cuts out ambiguous characters like:
48
49
 
49
- extra_rdoc_files:
50
- - Manifest.txt
50
+ * l : lowercase l (looks like a 1 : one)
51
+
52
+ * I : capital I (looks like a 1 : one)
53
+
54
+ * O : capital O (looks like a 0 : zero)
55
+
56
+
57
+ Based on work done by Tantek Çelik : http://tantek.pbworks.com/New_base_60'
58
+ email:
59
+ - veganstraightedge@example.com
60
+ executables:
61
+ - dec_to_sxg
62
+ - sxg_to_dec
63
+ extensions: []
64
+ extra_rdoc_files:
51
65
  - CHANGELOG.rdoc
66
+ - Manifest.txt
52
67
  - README.rdoc
53
- files:
68
+ files:
54
69
  - .autotest
55
70
  - CHANGELOG.rdoc
56
71
  - Manifest.txt
57
72
  - README.rdoc
58
73
  - Rakefile
59
74
  - lib/new_base_60.rb
75
+ - bin/dec_to_sxg
76
+ - bin/sxg_to_dec
60
77
  - test/test_new_base_60.rb
61
78
  - .gemtest
62
- has_rdoc: true
63
79
  homepage: http://github.com/veganstraightedge/new_base_60
64
80
  licenses: []
65
-
66
81
  post_install_message:
67
- rdoc_options:
82
+ rdoc_options:
68
83
  - --main
69
84
  - README.rdoc
70
- require_paths:
85
+ require_paths:
71
86
  - lib
72
- required_ruby_version: !ruby/object:Gem::Requirement
87
+ required_ruby_version: !ruby/object:Gem::Requirement
73
88
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
- version: "0"
81
- required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
94
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
- version: "0"
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
90
99
  requirements: []
91
-
92
100
  rubyforge_project: new_base_60
93
- rubygems_version: 1.5.2
101
+ rubygems_version: 1.8.24
94
102
  signing_key:
95
103
  specification_version: 3
96
- 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"
97
- test_files:
104
+ summary: ! 'Handy Conversion Sexagesimal (base 60) for Short URLs Cuts out ambiguous
105
+ characters like: * l : lowercase l (looks like a 1 : one) * I : capital I (looks
106
+ like a 1 : one) * O : capital O (looks like a 0 : zero) Based on work done by
107
+ Tantek Çelik : http://tantek.pbworks.com/New_base_60'
108
+ test_files:
98
109
  - test/test_new_base_60.rb