Skip to content

Commit

Permalink
renamed gem using @drbrain's conventions : http://blog.segment7.net/a…
Browse files Browse the repository at this point in the history
  • Loading branch information
veganstraightedge committed Nov 17, 2010
1 parent e7bf061 commit fcc35ee
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 51 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rdoc
@@ -1,3 +1,9 @@
=== 1.0.3 / 2010-11-16

* 1 minor enhancement

* Changed named from newbase60 to new_base_60

=== 1.0.2 / 2010-06-21

* 2 minor enhancement
Expand Down
4 changes: 2 additions & 2 deletions Manifest.txt
Expand Up @@ -3,5 +3,5 @@ CHANGELOG.rdoc
Manifest.txt
README.rdoc
Rakefile
lib/newbase60.rb
test/test_newbase60.rb
lib/new_base_60.rb
test/test_new_base_60.rb
14 changes: 7 additions & 7 deletions README.rdoc
@@ -1,6 +1,6 @@
= newbase60
= new_base_60

* http://github.com/veganstraightedge/NewBase60
* http://github.com/veganstraightedge/New_base_60

== DESCRIPTION:

Expand All @@ -10,7 +10,7 @@ Cuts out ambiguous characters like:
* I : capital I (looks like a 1 : one)
* O : capital O (looks like a 0 : zero)

Based on work done by Tantek Çelik : http://tantek.pbworks.com/NewBase60
Based on work done by Tantek Çelik : http://tantek.pbworks.com/New_base_60

== FEATURES/PROBLEMS:

Expand All @@ -22,8 +22,8 @@ Based on work done by Tantek Çelik : http://tantek.pbworks.com/NewBase60

How to use:

require "newbase60"
n = Newbase60.new("464")# => #<Newbase60:0x1011ea468 @base_60="464">
require "new_base_60"
n = New_base_60.new("464")# => #<New_base_60:0x1011ea468 @base_60="464">
puts n.to_i # => 14764
puts n.to_i.to_sxg # => "464"
puts n.to_date # => #<Date: 4910703/2,0,2299161>
Expand All @@ -32,15 +32,15 @@ How to use:

== INSTALL:

* sudo gem install newbase60
* sudo gem install new_base_60

== CREDITS:

* Original Idea : Tantek Çelik
* Ruby Port : Shane Becker
* Lotsa Cleanup : John Barnette

* sudo gem install newbase60
* sudo gem install new_base_60

== LICENSE:

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
@@ -1,7 +1,7 @@
require 'rubygems'
require 'hoe'

Hoe.spec 'newbase60' do
Hoe.spec 'new_base_60' do
developer('Shane Becker', 'veganstraightedge@example.com')

self.extra_rdoc_files = Dir["*.rdoc"]
Expand Down
19 changes: 7 additions & 12 deletions lib/newbase60.rb → lib/new_base_60.rb
@@ -1,7 +1,7 @@
require "date"
require "time"

class Newbase60
class New_base_60
VERSION = '1.0.2'
VOCABULARY = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz"

Expand Down Expand Up @@ -41,17 +41,15 @@ def to_i
def to_date
# HACK this is smelly
# days since epoch * seconds * minutes * hours + timezone
time = Time.at(Newbase60.new(@base_60).to_i *
time = Time.at(New_base_60.new(@base_60).to_i *
60 * 60 * 24 + Time.now.gmtoff.abs)

Date.parse(time.strftime("%Y/%m/%d"))
end
end

class Integer

# Converts a base 10 integer into a NewBase60 string.

# Converts a base 10 integer into a New_base_60 string.
def to_sxg
return "" if zero?

Expand All @@ -60,16 +58,15 @@ def to_sxg

while num > 0 do
mod = num % 60
sxg = "#{Newbase60::VOCABULARY[mod,1]}#{sxg}"
sxg = "#{New_base_60::VOCABULARY[mod,1]}#{sxg}"
num = (num - mod) / 60
end

sxg
end

# Converts a base 10 integer into a NewBase60 string, padding with
# leading zeroes.

# Converts a base 10 integer into a New_base_60 string,
# padding with leading zeroes.
def to_sxgf(padding)
num = self

Expand All @@ -88,9 +85,7 @@ def to_sxgf(padding)
end

class Date

# Converts into a NewBase60 string.

# Converts into a New_base_60 string.
def to_sxg
(self - Date.parse("1970/01/01")).to_i.to_sxg
end
Expand Down
29 changes: 29 additions & 0 deletions test/test_new_base_60.rb
@@ -0,0 +1,29 @@
require "test/unit"
require "new_base_60"

class TestNew_base_60 < Test::Unit::TestCase
def test_base60_to_base10
assert_equal New_base_60.new("464").to_i, 14764
assert_not_equal New_base_60.new("464").to_i, 12345
end

def test_base60_to_date
assert_equal New_base_60.new("464").to_date, Date.parse("2010/06/04")
assert_not_equal New_base_60.new("464").to_date, Date.parse("2010/06/05")
end

def test_date_to_base60
assert_equal Date.parse("2010/06/04").to_sxg, New_base_60.new("464").to_s
assert_not_equal Date.parse("2010/06/05").to_sxg, New_base_60.new("464")
end

def test_base10_to_base60
assert_equal 14764.to_sxg, "464"
assert_not_equal 12345.to_sxg, "464"
end

def test_base10_to_base60_with_leading_zeroes
assert_equal 14764.to_sxgf(9), "000000464"
assert_not_equal 12345.to_sxgf(9), "000000464"
end
end
29 changes: 0 additions & 29 deletions test/test_newbase60.rb

This file was deleted.

0 comments on commit fcc35ee

Please sign in to comment.