bizsh 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/bin/bizsh +5 -0
- data/bizcalc.gemspec +30 -0
- data/lib/bizsh.rb +103 -0
- data/lib/bizsh/version.rb +3 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f1a27a03a75b26f81f8c7140f661acce0bdebe2
|
4
|
+
data.tar.gz: bb381b0a17aea24b86b08825a96d2f9b1ecf07a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ceaeb75de2a84be432205b7100f60ad91030f491db34194154afde2eb26584cf9866d8c95c45d73d7c865fd7ad19e794c82885edac0284d6c15119b37b8303a
|
7
|
+
data.tar.gz: 575cca645e5d01316b70b5ee6fd25a54c0c3f02dcde0c2597b43d9b36536bc7c31867c97a78a1791d219422ad15db0bd1e88c841bed447cb26645344a112ddff
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Brad Gessler
|
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,40 @@
|
|
1
|
+
# Bizsh
|
2
|
+
|
3
|
+
An interactive ruby shell optimized business calculations.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Install the shell via rubygems:
|
8
|
+
|
9
|
+
$ gem install bizsh
|
10
|
+
|
11
|
+
Now fire up the shell!
|
12
|
+
|
13
|
+
$ bizsh
|
14
|
+
|
15
|
+
You're greated with an interactive Ruby shell that's optimized for business calculations.
|
16
|
+
|
17
|
+
bizsh> growth = '$ 100,000'.to_num.growth(150_000)
|
18
|
+
=> 0.5
|
19
|
+
bizsh> growth.to_s(:percent)
|
20
|
+
=> "50.00%"
|
21
|
+
bizsh> shares = 100
|
22
|
+
=> 100
|
23
|
+
bizsh> value = shares * "MSFT".quote.ask
|
24
|
+
=> 4759.0
|
25
|
+
|
26
|
+
## Why?
|
27
|
+
|
28
|
+
The calculator apps that ship on Mac and Windows are great for really basic calculations, but are lacking when a few variables need to be set to complete a calculation. Spreadsheets are great for building models or very complex calculations, but too heavy for running simpler calculations. There are desktop and online apps that do calculations, but are clunky or have ads all over the place.
|
29
|
+
|
30
|
+
I wrote `bizsh` after I found myself running a lot of common calculations in `irb`.
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Contributions for new functions, documentation, and tests are welcome!
|
35
|
+
|
36
|
+
1. Fork it ( https://github.com/bradgessler/bizsh/fork )
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/bizsh
ADDED
data/bizcalc.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bizsh/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bizsh"
|
8
|
+
spec.version = Bizsh::VERSION
|
9
|
+
spec.authors = ["Brad Gessler"]
|
10
|
+
spec.email = ["bradgessler@gmail.com"]
|
11
|
+
spec.summary = %q{An interactive ruby shell optimized business calculations.}
|
12
|
+
spec.homepage = "https://github.com/bradgessler/bizsh"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "pry"
|
25
|
+
spec.add_runtime_dependency "stock_quote", ">= 1.1.8"
|
26
|
+
# I have to include rest-client and mime-types on behalf of the stock_quote gem so
|
27
|
+
# that I don't get "WARN: Unresolved specs during Gem::Specification.reset" warnings
|
28
|
+
spec.add_runtime_dependency "rest-client", ">= 1.7.2"
|
29
|
+
spec.add_runtime_dependency "mime-types", ">= 2.3"
|
30
|
+
end
|
data/lib/bizsh.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require "bizsh/version"
|
2
|
+
require "pry"
|
3
|
+
|
4
|
+
module Bizsh
|
5
|
+
# Numerics that we'll refine.
|
6
|
+
NUMERIC_CLASSES = [Numeric, Float, Integer, Rational]
|
7
|
+
|
8
|
+
# String formatting for better ouput.
|
9
|
+
module Formatting
|
10
|
+
|
11
|
+
# Default the number of decimal places we show in strings.
|
12
|
+
DEFAULT_DECIMAL_PLACES = 2
|
13
|
+
|
14
|
+
# Format a number into a percentage.
|
15
|
+
FORMATTERS = {
|
16
|
+
percent: -> (value, *args) do
|
17
|
+
value = value * 100
|
18
|
+
value = FORMATTERS[:decimal].call(value, *args)
|
19
|
+
[value, '%'].join
|
20
|
+
end,
|
21
|
+
decimal: -> (value, places: DEFAULT_DECIMAL_PLACES) do
|
22
|
+
"%.#{places}f" % value.to_f
|
23
|
+
end
|
24
|
+
}
|
25
|
+
|
26
|
+
# Refine multiple types.
|
27
|
+
NUMERIC_CLASSES.each do |numeric|
|
28
|
+
refine numeric do
|
29
|
+
def to_s(format=nil, *args)
|
30
|
+
if formatter = FORMATTERS[format]
|
31
|
+
formatter.call(self, *args)
|
32
|
+
else
|
33
|
+
super()
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# All of the functions we'll use to calculate stuff.
|
41
|
+
module Functions
|
42
|
+
NUMERIC_CLASSES.each do |numeric|
|
43
|
+
refine numeric do
|
44
|
+
# Calculate growth rates.
|
45
|
+
def growth(present)
|
46
|
+
past = self.to_f
|
47
|
+
(present.to_f - past) / past
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Take string-ish numbers, like dollar amounts numbers with commas, and
|
54
|
+
# convert into a ruby number.
|
55
|
+
module ToNum
|
56
|
+
refine String do
|
57
|
+
def to_num
|
58
|
+
# TODO - Make this work for folks that don't use ",'s" in their numbers.
|
59
|
+
if match = self.match(/^\s*\$?\s*([\d\,]+)\.?(\d+)?\s*$/)
|
60
|
+
whole, decimal = match.captures
|
61
|
+
# Remove non-numeral out of the string.
|
62
|
+
whole.gsub!(/[^\d]/, '')
|
63
|
+
# Now cast it depending on if its a decimal value, or not.
|
64
|
+
if whole && decimal
|
65
|
+
[whole, '.', decimal].join.to_f
|
66
|
+
elsif whole && !decimal
|
67
|
+
whole.to_i
|
68
|
+
end
|
69
|
+
else
|
70
|
+
0 # or should we just blow up?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
module Stocks
|
77
|
+
refine String do
|
78
|
+
require "stock_quote"
|
79
|
+
|
80
|
+
def quote
|
81
|
+
StockQuote::Stock.quote(self)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class REPL
|
87
|
+
# REPL prompt.
|
88
|
+
NAME = 'bizsh'
|
89
|
+
|
90
|
+
# Refine all of our types.
|
91
|
+
using Functions
|
92
|
+
using Formatting
|
93
|
+
using ToNum
|
94
|
+
using Stocks
|
95
|
+
|
96
|
+
# Start a REPL with refined types.
|
97
|
+
def start
|
98
|
+
Pry.hooks.clear_all # Remove default pry hooks.
|
99
|
+
Pry.config.prompt = proc { |_, nest_level, _| "#{NAME}> " } # bizsh prompt.
|
100
|
+
Pry.start binding # Fire up the REPL.
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bizsh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brad Gessler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-20 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.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: stock_quote
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.1.8
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.1.8
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rest-client
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.7.2
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.7.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mime-types
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.3'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.3'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- bradgessler@gmail.com
|
114
|
+
executables:
|
115
|
+
- bizsh
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/bizsh
|
125
|
+
- bizcalc.gemspec
|
126
|
+
- lib/bizsh.rb
|
127
|
+
- lib/bizsh/version.rb
|
128
|
+
homepage: https://github.com/bradgessler/bizsh
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.2.2
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: An interactive ruby shell optimized business calculations.
|
152
|
+
test_files: []
|