bassy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/README.md +45 -0
- data/Rakefile +15 -0
- data/bassy.gemspec +34 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/bassy.rb +53 -0
- data/lib/bassy/version.rb +3 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 62c6bea054e83b3cd1d731cfbcb37b2704b3f788
|
4
|
+
data.tar.gz: d7b74ae3ff6bb08e9c3a66545883c894c43ca4fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 22fb7d51308547ca73b00e0f4e59b387b259f1a96dfdbfc815029761e44a58c2b677b9ec4b9a2b0c207d424a15edcc2f84415723fdc8c42c7fecdb13db8ab6a9
|
7
|
+
data.tar.gz: 9243ade0c22b2f88d1b4291c1342043dddf3f1f1a3cf86570592ffb5bcc73724b52838bd9460cdf9a09b760bdec0653cbdf5979b70a287146d27e8478b22e90f
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Bassy
|
2
|
+
A simple gem to convert a number between bases.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'bassy'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install bassy
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Bassy has only one function included in the module
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'bassy'
|
26
|
+
|
27
|
+
Bassy.convert(10,10,8) # converting 10 from decimal to octal
|
28
|
+
#=> 12
|
29
|
+
```
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
|
+
|
35
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pawandubey/bassy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
40
|
+
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the Apache License Version 2.
|
45
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
|
5
|
+
#Rake::TestTask.new(:test) do |t|
|
6
|
+
# t.libs << "test"
|
7
|
+
# t.libs << "lib"
|
8
|
+
# t.test_files = FileList['test/**/*_test.rb']
|
9
|
+
#end
|
10
|
+
|
11
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
12
|
+
task.rspec_opts = ['--color', '--format d']
|
13
|
+
end
|
14
|
+
|
15
|
+
task :default => :spec
|
data/bassy.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bassy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bassy"
|
8
|
+
spec.version = Bassy::VERSION
|
9
|
+
spec.authors = ["Pawan Dubey"]
|
10
|
+
spec.email = ["pawandubey@outlook.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A simple gem to convert a number between two bases.}
|
13
|
+
spec.description = %q{Bassy takes a number and convert it from a given base to the specified base.}
|
14
|
+
spec.homepage = "https://github.com/pawandubey/bassy"
|
15
|
+
spec.license = "Apache License Version 2"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec"
|
34
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bassy"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/bassy.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "bassy/version"
|
2
|
+
|
3
|
+
module Bassy
|
4
|
+
def self.convert(number, from, *too)
|
5
|
+
from = from.to_s
|
6
|
+
number = number.to_s
|
7
|
+
|
8
|
+
if too.empty?
|
9
|
+
to = 10.to_s
|
10
|
+
else
|
11
|
+
to = too.first.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
fail ArgumentError if [from, to].any? { |a| !(2..36).include? a.to_i }
|
15
|
+
|
16
|
+
if from == to
|
17
|
+
return number
|
18
|
+
else
|
19
|
+
convert_base(number, from, to)
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def self.convert_base(number, from, to)
|
27
|
+
mapping = create_mapping
|
28
|
+
dec = number.chars.reduce(0) do |conv, c|
|
29
|
+
conv = conv * from.to_i + mapping[c]
|
30
|
+
end
|
31
|
+
|
32
|
+
reverse_mapping = mapping.invert
|
33
|
+
conv = ""
|
34
|
+
|
35
|
+
while dec > 0
|
36
|
+
conv << reverse_mapping[dec % to.to_i]
|
37
|
+
dec /= to.to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
conv.reverse
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.create_mapping
|
44
|
+
h = {}
|
45
|
+
keys = ('0'..'9').to_a
|
46
|
+
values = (0..9).to_a
|
47
|
+
keys.zip(values) { |k,v| h[k] = v }
|
48
|
+
keys = ('A'..'Z').to_a
|
49
|
+
values = (10..35).to_a
|
50
|
+
keys.zip(values) { |k,v| h[k] = v }
|
51
|
+
h
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bassy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pawan Dubey
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-21 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Bassy takes a number and convert it from a given base to the specified
|
56
|
+
base.
|
57
|
+
email:
|
58
|
+
- pawandubey@outlook.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bassy.gemspec
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/bassy.rb
|
73
|
+
- lib/bassy/version.rb
|
74
|
+
homepage: https://github.com/pawandubey/bassy
|
75
|
+
licenses:
|
76
|
+
- Apache License Version 2
|
77
|
+
metadata:
|
78
|
+
allowed_push_host: https://rubygems.org
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.8
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: A simple gem to convert a number between two bases.
|
99
|
+
test_files: []
|