new_base60 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae12d3a2918f684c62d1c3827ea0aad4e0688d64
4
+ data.tar.gz: 96863b1263f64f8e3133de2b1aabc6dccad815bb
5
+ SHA512:
6
+ metadata.gz: 4ad734e394aba12e7981f7d9c62628ed1e8398dc6279682c7a423745bd053b50a164629a799f3ba75c6298f62dadd0cf67d41fd63d55c9a150831420b14c4d4e
7
+ data.tar.gz: 4aac4d52caf78935fea967dc625143b662bcb0cc4cca7f3852a6d1715ded548a8c73a3cb090c0ddd564bc5a85985d56041176240ca0c8f4c694b56b6349de8ea
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in new_base60.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Andrew Donaldson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # NewBase60
2
+
3
+ My interpretation of Tantek Çelik's NewBase60:
4
+
5
+ * http://tantek.pbworks.com/w/page/19402946/NewBase60
6
+ * http://tantek.pbworks.com/w/page/21743973/Whistle
7
+
8
+ Although another ruby port existed, I fancied rolling my own.
9
+ It can be found here:
10
+
11
+ https://github.com/veganstraightedge/new_base_60
12
+
13
+ For sanity checks I copied some of their tests and outputs. For laziness (and because their readme was pretty good) I've ripped most of their Readme.
14
+
15
+ ## Description
16
+
17
+ Handy Conversion Sexagesimal (base 60) for Short URLs
18
+ Cuts out ambiguous characters like:
19
+
20
+ * `l` : lowercase `L` (looks like a `1` : one)
21
+ * `I` : capital `i` (looks like a `1` : one)
22
+ * `O` : capital `o` (looks like a `0` : zero)
23
+
24
+ Based on work done by Tantek Çelik : [http://ttk.me/w/NewBase60](http://ttk.me/w/NewBase60 "tantek / NewBase60")
25
+
26
+ ## Features/Problems
27
+
28
+ * Holds off on the monkey patching at the expense of being slightly more clunky
29
+ * Converts Base10 to Base60 (147124 becomes fs4)
30
+ * Converts Base60 to Base10 (fs4 becomes 147124)
31
+ * Converts Base60 to a Date object (464 becomes 4 June 2010)
32
+ * Converts a Date to Base60 (5 June 2012 becomes 4JG)
33
+
34
+ ## Synopsis
35
+
36
+ How to use:
37
+
38
+ ```ruby
39
+ require "new_base60"
40
+
41
+ NewBase60::Sxg.new('10').to_i # => 60
42
+ NewBase60::Sxg.new('464').to_date # => #<Date: 2010-06-04 ((2455352j,0s,0n),+0s,2299161j)>
43
+ NewBase60::Base10.new(147124).to_sxg # => "fs4"
44
+
45
+ NewBase60::SxgDate.new(2012, 6, 5).to_sxg # => "4JG"
46
+ # or
47
+ d = Date.new(2014, 6, 5)
48
+ NewBase60::SxgDate.new_from_date(d).to_sxg # => "4WS"
49
+ ```
50
+
51
+ ## Install
52
+
53
+ Add this line to your application's Gemfile:
54
+
55
+ ```ruby
56
+ gem 'new_base60'
57
+ ```
58
+
59
+ And then execute:
60
+
61
+ $ bundle
62
+
63
+ Or install it yourself as:
64
+
65
+ $ gem install new_base60
66
+ ``
67
+
68
+ # Credits
69
+ ## Contributors
70
+
71
+ * [Original Idea](http://tantek.com/w/NewBase60 "tantek / NewBase60") : [Tantek Çelik](http://tantek.com "tantek.com") ([@tantek](https://github.com/tantek))
72
+ * Other Ruby Port : [Shane Becker](http://iamshane.com "I&#x27;m Shane Becker") ([@veganstraightedge](https://github.com/veganstraightedge))
73
+
74
+ ## License
75
+
76
+ **PUBLIC DOMAIN**
77
+
78
+ Your heart is as free as the air you breathe. <br>
79
+ The ground you stand on is liberated territory.
80
+
81
+ In legal text, new_base60 is dedicated to the public domain
82
+ using Creative Commons -- CC0 1.0 Universal.
83
+
84
+ [http://creativecommons.org/publicdomain/zero/1.0](http://creativecommons.org/publicdomain/zero/1.0 "Creative Commons &mdash; CC0 1.0 Universal")
85
+
86
+ ## Contributing
87
+
88
+ 1. Fork it ( https://github.com/[my-github-username]/new_base60/fork )
89
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
90
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
91
+ 4. Push to the branch (`git push origin my-new-feature`)
92
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/new_base60.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "new_base60/version"
2
+ require "new_base60/base10"
3
+ require "new_base60/sxg"
4
+ require "new_base60/sxg_date"
5
+
6
+ module NewBase60
7
+ end
@@ -0,0 +1,28 @@
1
+ module NewBase60
2
+ class Base10
3
+ attr_reader :value
4
+
5
+ def initialize(value, args = {})
6
+ @value = value
7
+ end
8
+
9
+ def self.vocabulary
10
+ '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz'
11
+ end
12
+
13
+ def to_sxg
14
+ return value.to_s if value < 10
15
+
16
+ output = []
17
+ nn = value
18
+
19
+ while nn > 0
20
+ dd = nn % 60
21
+ output.unshift(self.class.vocabulary.chars[dd])
22
+ nn = (nn - dd) / 60
23
+ end
24
+
25
+ output.join
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ module NewBase60
2
+ class Sxg
3
+ attr_reader :value
4
+
5
+ def initialize(value)
6
+ @value = value
7
+ end
8
+
9
+ def self.vocabulary
10
+ '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz'
11
+ end
12
+
13
+ def to_i
14
+ value.chars.inject(0) { |sum, char| sum = (60 * sum) + self.class.vocabulary.index(char) }
15
+ end
16
+
17
+ def to_date
18
+ Date.new(1970, 1, 1) + to_i
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module NewBase60
2
+ class SxgDate < Date
3
+ def self.new_from_date(date)
4
+ new(date.year, date.month, date.day)
5
+ end
6
+
7
+ def to_sxg
8
+ Base10.new(days_since_epoch).to_sxg
9
+ end
10
+
11
+ def days_since_epoch
12
+ (self - Date.new(1970, 1, 1)).to_i
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module NewBase60
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'new_base60/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "new_base60"
8
+ spec.version = NewBase60::VERSION
9
+ spec.authors = ["Andrew Donaldson"]
10
+ spec.email = ["andrew@desto.net"]
11
+ spec.summary = %q{Library to ease converting between NewBase60 and Fixnums, dates}
12
+ spec.description = %q{NewBase60 is useful as part of a personal URL shortener which itself is an important component of a POSSE (http://indiewebcamp.com/POSSE)}
13
+ spec.homepage = ""
14
+ spec.license = "Public Domain"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.1"
24
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/new_base60/base10'
3
+
4
+ RSpec.describe 'NewBase60::Base10' do
5
+ describe 'to_sxg' do
6
+ it 'returns a string' do
7
+ expect(NewBase60::Base10.new(0).to_sxg).to be_a String
8
+ end
9
+
10
+ it 'returns correct values for single values' do
11
+ expect(NewBase60::Base10.new(0).to_sxg).to eq '0'
12
+
13
+ (1..9).each do |value|
14
+ expect(NewBase60::Base10.new(value).to_sxg).to eq value.to_s
15
+ end
16
+
17
+ expect(NewBase60::Base10.new(10).to_sxg).to eq 'A'
18
+ expect(NewBase60::Base10.new(11).to_sxg).to eq 'B'
19
+ expect(NewBase60::Base10.new(12).to_sxg).to eq 'C'
20
+ expect(NewBase60::Base10.new(13).to_sxg).to eq 'D'
21
+ expect(NewBase60::Base10.new(14).to_sxg).to eq 'E'
22
+ expect(NewBase60::Base10.new(15).to_sxg).to eq 'F'
23
+ expect(NewBase60::Base10.new(16).to_sxg).to eq 'G'
24
+ expect(NewBase60::Base10.new(17).to_sxg).to eq 'H'
25
+ expect(NewBase60::Base10.new(18).to_sxg).to eq 'J'
26
+ expect(NewBase60::Base10.new(19).to_sxg).to eq 'K'
27
+ expect(NewBase60::Base10.new(20).to_sxg).to eq 'L'
28
+ expect(NewBase60::Base10.new(21).to_sxg).to eq 'M'
29
+ expect(NewBase60::Base10.new(22).to_sxg).to eq 'N'
30
+ expect(NewBase60::Base10.new(23).to_sxg).to eq 'P'
31
+ expect(NewBase60::Base10.new(24).to_sxg).to eq 'Q'
32
+ expect(NewBase60::Base10.new(25).to_sxg).to eq 'R'
33
+ expect(NewBase60::Base10.new(26).to_sxg).to eq 'S'
34
+ expect(NewBase60::Base10.new(27).to_sxg).to eq 'T'
35
+ expect(NewBase60::Base10.new(28).to_sxg).to eq 'U'
36
+ expect(NewBase60::Base10.new(29).to_sxg).to eq 'V'
37
+ expect(NewBase60::Base10.new(30).to_sxg).to eq 'W'
38
+ expect(NewBase60::Base10.new(31).to_sxg).to eq 'X'
39
+ expect(NewBase60::Base10.new(32).to_sxg).to eq 'Y'
40
+ expect(NewBase60::Base10.new(33).to_sxg).to eq 'Z'
41
+ expect(NewBase60::Base10.new(34).to_sxg).to eq '_'
42
+ expect(NewBase60::Base10.new(35).to_sxg).to eq 'a'
43
+ expect(NewBase60::Base10.new(36).to_sxg).to eq 'b'
44
+ expect(NewBase60::Base10.new(37).to_sxg).to eq 'c'
45
+ expect(NewBase60::Base10.new(38).to_sxg).to eq 'd'
46
+ expect(NewBase60::Base10.new(39).to_sxg).to eq 'e'
47
+ expect(NewBase60::Base10.new(40).to_sxg).to eq 'f'
48
+ expect(NewBase60::Base10.new(41).to_sxg).to eq 'g'
49
+ expect(NewBase60::Base10.new(42).to_sxg).to eq 'h'
50
+ expect(NewBase60::Base10.new(43).to_sxg).to eq 'i'
51
+ expect(NewBase60::Base10.new(44).to_sxg).to eq 'j'
52
+ expect(NewBase60::Base10.new(45).to_sxg).to eq 'k'
53
+ expect(NewBase60::Base10.new(46).to_sxg).to eq 'm'
54
+ expect(NewBase60::Base10.new(47).to_sxg).to eq 'n'
55
+ expect(NewBase60::Base10.new(48).to_sxg).to eq 'o'
56
+ expect(NewBase60::Base10.new(49).to_sxg).to eq 'p'
57
+ expect(NewBase60::Base10.new(50).to_sxg).to eq 'q'
58
+ expect(NewBase60::Base10.new(51).to_sxg).to eq 'r'
59
+ expect(NewBase60::Base10.new(52).to_sxg).to eq 's'
60
+ expect(NewBase60::Base10.new(53).to_sxg).to eq 't'
61
+ expect(NewBase60::Base10.new(54).to_sxg).to eq 'u'
62
+ expect(NewBase60::Base10.new(55).to_sxg).to eq 'v'
63
+ expect(NewBase60::Base10.new(56).to_sxg).to eq 'w'
64
+ expect(NewBase60::Base10.new(57).to_sxg).to eq 'x'
65
+ expect(NewBase60::Base10.new(58).to_sxg).to eq 'y'
66
+ expect(NewBase60::Base10.new(59).to_sxg).to eq 'z'
67
+ end
68
+
69
+ it 'converts base 10 to base 60' do
70
+ expect(NewBase60::Base10.new(60).to_sxg).to eq '10'
71
+ expect(NewBase60::Base10.new(14764).to_sxg).to eq '464'
72
+ expect(NewBase60::Base10.new(147124).to_sxg).to eq 'fs4'
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,15 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+
10
+ config.disable_monkey_patching!
11
+ config.order = :random
12
+
13
+ config.filter_run :focus
14
+ config.run_all_when_everything_filtered = true
15
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/new_base60/sxg_date'
3
+
4
+ RSpec.describe 'NewBase60::SxgDate' do
5
+ it 'is of type date' do
6
+ expect(NewBase60::SxgDate.new).to be_a Date
7
+ end
8
+
9
+ describe 'new_from_date' do
10
+ it 'will return an SxgDate comparable with the passed in date' do
11
+ test_date = Date.new(2010, 06, 04)
12
+ sxg_date = NewBase60::SxgDate.new_from_date(test_date)
13
+ expect(sxg_date <=> test_date).to eq 0
14
+ end
15
+ end
16
+
17
+ describe 'to_sxg' do
18
+ it 'will return the date as an sxg value' do
19
+ expect(NewBase60::SxgDate.new(1970, 1, 1).to_sxg).to eq '0'
20
+ expect(NewBase60::SxgDate.new(2010, 06, 04).to_sxg).to eq '464'
21
+ expect(NewBase60::SxgDate.new(2012, 06, 05).to_sxg).to eq '4JG'
22
+ end
23
+ end
24
+ end
data/spec/sxg_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/new_base60/sxg'
3
+
4
+ RSpec.describe 'NewBase60::Sxg' do
5
+ describe 'to_i' do
6
+ it 'returns an integer' do
7
+ expect(NewBase60::Sxg.new('').to_i).to be_a Fixnum
8
+ end
9
+
10
+ it 'converts the sxg value to an integer' do
11
+ expect(NewBase60::Sxg.new('A').to_i).to eq 10
12
+ expect(NewBase60::Sxg.new('10').to_i).to eq 60
13
+ expect(NewBase60::Sxg.new('fs4').to_i).to eq 147124
14
+ end
15
+ end
16
+
17
+ describe 'to_date' do
18
+ it 'will return the epoch for an empty string' do
19
+ expect(NewBase60::Sxg.new('').to_date).to eq Date.new(1970, 1, 1)
20
+ end
21
+
22
+ it 'will return the epoch date plus sxg converted value of days' do
23
+ expect(NewBase60::Sxg.new('1').to_date).to eq Date.new(1970, 1, 2)
24
+ expect(NewBase60::Sxg.new('464').to_date).to eq Date.new(2010, 06, 04)
25
+ expect(NewBase60::Sxg.new('4JG').to_date).to eq Date.new(2012, 06, 05)
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: new_base60
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Donaldson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ description: NewBase60 is useful as part of a personal URL shortener which itself
56
+ is an important component of a POSSE (http://indiewebcamp.com/POSSE)
57
+ email:
58
+ - andrew@desto.net
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/new_base60.rb
70
+ - lib/new_base60/base10.rb
71
+ - lib/new_base60/sxg.rb
72
+ - lib/new_base60/sxg_date.rb
73
+ - lib/new_base60/version.rb
74
+ - new_base60.gemspec
75
+ - spec/base10_spec.rb
76
+ - spec/spec_helper.rb
77
+ - spec/sxg_date_spec.rb
78
+ - spec/sxg_spec.rb
79
+ homepage: ''
80
+ licenses:
81
+ - Public Domain
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.2.2
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Library to ease converting between NewBase60 and Fixnums, dates
103
+ test_files:
104
+ - spec/base10_spec.rb
105
+ - spec/spec_helper.rb
106
+ - spec/sxg_date_spec.rb
107
+ - spec/sxg_spec.rb