Skip to content

Commit

Permalink
Changed class name from new_base_60 to NewBase60
Browse files Browse the repository at this point in the history
  • Loading branch information
veganstraightedge committed Feb 16, 2011
1 parent 8a70522 commit b175d3b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
=== 1.0.4 / 2011-02-15

* 1 minor enhancement

* Changed class name from new_base_60 to NewBase60

=== 1.0.3 / 2010-11-16

* 1 minor enhancement
Expand Down
12 changes: 6 additions & 6 deletions lib/new_base_60.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "date"
require "time"

class New_base_60
class NewBase60
VERSION = '1.0.3'
VOCABULARY = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz"

Expand Down Expand Up @@ -41,15 +41,15 @@ def to_i
def to_date
# HACK this is smelly
# days since epoch * seconds * minutes * hours + timezone
time = Time.at(New_base_60.new(@base_60).to_i *
time = Time.at(NewBase60.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 New_base_60 string.
# Converts a base 10 integer into a NewBase60 string.
def to_sxg
return "" if zero?

Expand All @@ -58,14 +58,14 @@ def to_sxg

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

sxg
end

# Converts a base 10 integer into a New_base_60 string,
# Converts a base 10 integer into a NewBase60 string,
# padding with leading zeroes.
def to_sxgf(padding)
num = self
Expand All @@ -85,7 +85,7 @@ def to_sxgf(padding)
end

class Date
# Converts into a New_base_60 string.
# Converts into a NewBase60 string.
def to_sxg
(self - Date.parse("1970/01/01")).to_i.to_sxg
end
Expand Down
14 changes: 7 additions & 7 deletions test/test_new_base_60.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
require "test/unit"
require "new_base_60"

class TestNew_base_60 < Test::Unit::TestCase
class TestNewBase60 < 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
assert_equal NewBase60.new("464").to_i, 14764
assert_not_equal NewBase60.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")
assert_equal NewBase60.new("464").to_date, Date.parse("2010/06/04")
assert_not_equal NewBase60.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")
assert_equal Date.parse("2010/06/04").to_sxg, NewBase60.new("464").to_s
assert_not_equal Date.parse("2010/06/05").to_sxg, NewBase60.new("464")
end

def test_base10_to_base60
Expand Down

0 comments on commit b175d3b

Please sign in to comment.