base_n 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/base_n +48 -0
- data/lib/base_n/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaec7f18d7a2575fafa2a55dc7ef71f2a25602de
|
4
|
+
data.tar.gz: 5bffccc8308fbe05fdce15922d95d91fe21576be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c40a41015d6d7b230baca980ce29c890fb741881152bd2f962f85dba146137fe48f840684a9291bbc73e8a87423f50428db7ac5d0a771805b1ea946922257321
|
7
|
+
data.tar.gz: cf286283eef2ab3d1ea4e8e8b1f1bbfb38542a4f1c9dbb6ec12ee8efaafbd69521237f054f85b1b1769123a211df7ed710546b3f678767904f1eca2c219bb5f7
|
data/bin/base_n
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
options = {
|
6
|
+
from_base: 10,
|
7
|
+
to_base: 16,
|
8
|
+
quiet: false
|
9
|
+
}
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: base_n [options]"
|
12
|
+
|
13
|
+
opts.on("-q", "--[no-]quiet", "Run with minimal output") do |v|
|
14
|
+
options[:quiet] = v
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on('-f', '--from-base [base]', 'Base to convert from (default: 10)') do |b|
|
18
|
+
options[:from_base] = b.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-t', '--to-base [base]', 'Base to convert to (default: 16)') do |b|
|
22
|
+
options[:to_base] = b.to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on('-n', '--from-number NUMBER', 'Number to convert between bases') do |n|
|
26
|
+
options[:number] = n
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
30
|
+
puts opts
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
end.parse!
|
34
|
+
|
35
|
+
if options[:number].nil?
|
36
|
+
puts "Needs -n number"
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
|
40
|
+
require 'base_n'
|
41
|
+
|
42
|
+
n = BaseN::Number.new options[:number], options[:from_base]
|
43
|
+
i = n.rebase options[:to_base]
|
44
|
+
if $stdout.tty? && !options[:quiet]
|
45
|
+
puts "%s in base %s => %s in base %s" % [ options[:number], options[:from_base], i.to_s, options[:to_base] ]
|
46
|
+
else
|
47
|
+
puts i.to_s
|
48
|
+
end
|
data/lib/base_n/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base_n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig R Webster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -41,7 +41,8 @@ dependencies:
|
|
41
41
|
description: Base 2, 10 and 64 aren't the only bases.
|
42
42
|
email:
|
43
43
|
- craig@barkingiguana.com
|
44
|
-
executables:
|
44
|
+
executables:
|
45
|
+
- base_n
|
45
46
|
extensions: []
|
46
47
|
extra_rdoc_files: []
|
47
48
|
files:
|
@@ -51,6 +52,7 @@ files:
|
|
51
52
|
- README.md
|
52
53
|
- Rakefile
|
53
54
|
- base_n.gemspec
|
55
|
+
- bin/base_n
|
54
56
|
- lib/base_n.rb
|
55
57
|
- lib/base_n/version.rb
|
56
58
|
homepage: ''
|