encode_with_alphabet 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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
data/.rvmrc ADDED
@@ -0,0 +1,6 @@
1
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
2
+ && -s "${rvm_path:-$HOME/.rvm}/environments/ruby-1.8.7@encode_with_alphabet" ]] ; then
3
+ \. "${rvm_path:-$HOME/.rvm}/environments/ruby-1.8.7@encode_with_alphabet"
4
+ else
5
+ rvm --create "ruby-1.8.7@encode_with_alphabet"
6
+ fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in encode_with_alphabet.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "encode_with_alphabet/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "encode_with_alphabet"
7
+ s.version = EncodeWithAlphabet::VERSION
8
+ s.authors = ["Alexander Glushkov"]
9
+ s.email = ["cutalion@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Encode integers with provided alphabet}
12
+ s.description = %q{Allows you to encode any integers with any alphabet}
13
+
14
+ s.rubyforge_project = "encode_with_alphabet"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec", "~> 2.0"
22
+ end
@@ -0,0 +1,25 @@
1
+ require "encode_with_alphabet/version"
2
+
3
+ module EncodeWithAlphabet
4
+ def self.encode(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')
5
+ raise 'number must be an integer' unless number.is_a? Fixnum
6
+ raise 'alphabet must be non-empty' if alphabet.empty?
7
+
8
+ return alphabet[0,1] if number == 0
9
+
10
+ base = ''
11
+ sign = ''
12
+
13
+ if number < 0
14
+ sign = '-'
15
+ number = - number
16
+ end
17
+
18
+ while number != 0
19
+ number, i = number.divmod alphabet.size
20
+ base = alphabet[i, 1] + base
21
+ end
22
+
23
+ return sign + base
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module EncodeWithAlphabet
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ module EncodeWithAlphabet
4
+ describe "#encode" do
5
+ subject { EncodeWithAlphabet.encode(number, alphabet) }
6
+ context "when alphabet is '01'" do
7
+ let(:alphabet) { '01' }
8
+
9
+ context 'when number is 0' do
10
+ let(:number) { 0 }
11
+ it { should == '0' }
12
+ end
13
+
14
+ context 'when number is 1' do
15
+ let(:number) { 1 }
16
+ it { should == '1' }
17
+ end
18
+
19
+ context 'when number is 10' do
20
+ let(:number) { 10 }
21
+ it { should == '1010' }
22
+ end
23
+ end
24
+
25
+ context "when alphabet is '0123456789abcdefghijklmnopqrstuvwxyzABC'" do
26
+ let(:alphabet) { '0123456789abcdefghijklmnopqrstuvwxyzABC' }
27
+
28
+ context 'when number is 0' do
29
+ let(:number) { 0 }
30
+ it { should == '0' }
31
+ end
32
+
33
+ context 'when number is 1' do
34
+ let(:number) { 1 }
35
+ it { should == '1' }
36
+ end
37
+
38
+ context 'when number is 10' do
39
+ let(:number) { 10 }
40
+ it { should == 'a' }
41
+ end
42
+
43
+ context 'when number is 39' do
44
+ let(:number) { 39 }
45
+ it { should == '10' }
46
+ end
47
+
48
+ context 'when number is 42' do
49
+ let(:number) { 42 }
50
+ it { should == '13' }
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
2
+ require 'encode_with_alphabet'
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: encode_with_alphabet
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Alexander Glushkov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 2
31
+ - 0
32
+ version: "2.0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Allows you to encode any integers with any alphabet
36
+ email:
37
+ - cutalion@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - .rvmrc
47
+ - Gemfile
48
+ - Rakefile
49
+ - encode_with_alphabet.gemspec
50
+ - lib/encode_with_alphabet.rb
51
+ - lib/encode_with_alphabet/version.rb
52
+ - spec/encode_with_alphabet_spec.rb
53
+ - spec/spec_helper.rb
54
+ homepage: ""
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project: encode_with_alphabet
83
+ rubygems_version: 1.8.6
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Encode integers with provided alphabet
87
+ test_files: []
88
+