base_n 0.0.3 → 0.0.4

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/base_n +48 -0
  3. data/lib/base_n/version.rb +1 -1
  4. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc44f904032ae1d89015105c51a091e95aeaf017
4
- data.tar.gz: f0d58f083f5e9943ce7c78e25bdac670d0341a64
3
+ metadata.gz: aaec7f18d7a2575fafa2a55dc7ef71f2a25602de
4
+ data.tar.gz: 5bffccc8308fbe05fdce15922d95d91fe21576be
5
5
  SHA512:
6
- metadata.gz: 229c56c05698f09800d474508445a94cc5f0f4d0d92fc93b4a33d4079af6e5ee7ecc5c3d82e98e57558d9bf70a4108c239b14156c230260d3c8a8f9246338fcb
7
- data.tar.gz: 1f844cddf8311057ed0010eb7833cbd693bf035234c272a321da7e19739a21dbc7498372c3fd92935a31ec7a2e05dc02bd45c5f87d9c85d31c2a5afc2d8bc391
6
+ metadata.gz: c40a41015d6d7b230baca980ce29c890fb741881152bd2f962f85dba146137fe48f840684a9291bbc73e8a87423f50428db7ac5d0a771805b1ea946922257321
7
+ data.tar.gz: cf286283eef2ab3d1ea4e8e8b1f1bbfb38542a4f1c9dbb6ec12ee8efaafbd69521237f054f85b1b1769123a211df7ed710546b3f678767904f1eca2c219bb5f7
@@ -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
@@ -1,3 +1,3 @@
1
1
  module BaseN
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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-08-07 00:00:00.000000000 Z
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: ''