Class: NewBase60
- Inherits:
-
Object
- Object
- NewBase60
- Defined in:
- lib/new_base_60.rb
Constant Summary collapse
- VERSION =
'1.1.2'
- VOCABULARY =
"0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz"
Instance Method Summary collapse
-
#initialize(base_60) ⇒ NewBase60
constructor
A new instance of NewBase60.
-
#to_date ⇒ Object
Converts into a Date.
-
#to_i ⇒ Object
Converts into a base 10 integer.
- #to_s ⇒ Object
Constructor Details
#initialize(base_60) ⇒ NewBase60
Returns a new instance of NewBase60.
8 9 10 |
# File 'lib/new_base_60.rb', line 8 def initialize(base_60) @base_60 = base_60 end |
Instance Method Details
#to_date ⇒ Object
Converts into a Date.
41 42 43 |
# File 'lib/new_base_60.rb', line 41 def to_date Time.at(to_i * 60 * 60 * 24).utc.to_date end |
#to_i ⇒ Object
Converts into a base 10 integer.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/new_base_60.rb', line 17 def to_i num = 0 @base_60.bytes do |char| case char when 48..57 then char -= 48 when 65..72 then char -= 55 when 73, 108 then char = 1 # typo capital I, lowercase l to 1 when 74..78 then char -= 56 when 79 then char = 0 # error correct typo capital O to 0 when 80..90 then char -= 57 when 95 then char = 34 when 97..107 then char -= 62 when 109..122 then char -= 63 else char = 0 # treat all other noise as 0 end num = 60 * num + char end num end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/new_base_60.rb', line 12 def to_s @base_60 end |