little_math_pet 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: abb3df9de9acef475450684669e2a90f5a5191b7
4
+ data.tar.gz: 41645a51bc37210294cef67f5b9617a2639f9412
5
+ SHA512:
6
+ metadata.gz: aa54987d12343669c68eb0f4dace4e1c94d8c1aacab913323c7020b05e6b352af552408a0f6778348f366401d346e4ce4b308c1b13895664218eeb6fbae0ef3c
7
+ data.tar.gz: 80fc19e31e0c3a46c3be7ac4198bf5fca1bc50a4737c8110c3b2d86d4881a355f15f6b5911307ab2de6e4c828d12fb889ee9a78b62584c4d610eced234fee32a
metadata CHANGED
@@ -1,114 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: little_math_pet
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.4.0
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kostas Karachalios
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-01-08 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: bundler
16
- version_requirements: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 1.0.0
22
- requirement: !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ~>
26
- - !ruby/object:Gem::Version
27
- version: 1.0.0
28
- prerelease: false
29
- type: :runtime
30
- - !ruby/object:Gem::Dependency
31
- name: jeweler
32
- version_requirements: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: 1.5.2
38
- requirement: !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: 1.5.2
44
- prerelease: false
45
- type: :runtime
46
- - !ruby/object:Gem::Dependency
47
- name: rspec
48
- version_requirements: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: 2.5.0
54
- requirement: !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ~>
58
- - !ruby/object:Gem::Version
59
- version: 2.5.0
60
- prerelease: false
61
- type: :runtime
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
+ dependencies: []
62
13
  description: LittleMathPet understands simple math expressions in string format with
63
- mutliple variables and returns the result of the expression
14
+ multiple variables and returns the result of the expression
64
15
  email: kostas.karachalios@me.com
65
16
  executables: []
66
17
  extensions: []
67
- extra_rdoc_files:
68
- - LICENSE.txt
69
- - README.rdoc
18
+ extra_rdoc_files: []
70
19
  files:
71
- - .document
72
- - .ruby-version
73
- - .travis.yml
74
- - Gemfile
75
- - Gemfile.lock
76
- - LICENSE.txt
77
- - README.rdoc
78
- - Rakefile
79
- - VERSION
80
20
  - lib/little_math_pet.rb
81
- - little_math_pet.gemspec
82
- - spec/little_math_pet_spec.rb
83
- - spec/spec_helper.rb
84
21
  homepage: http://github.com/vrinek/little-math-pet
85
22
  licenses:
86
23
  - MIT
24
+ metadata: {}
87
25
  post_install_message:
88
26
  rdoc_options: []
89
27
  require_paths:
90
28
  - lib
91
29
  required_ruby_version: !ruby/object:Gem::Requirement
92
- none: false
93
30
  requirements:
94
- - - '>='
31
+ - - ">="
95
32
  - !ruby/object:Gem::Version
96
- segments:
97
- - 0
98
- hash: -4137418140742752699
99
33
  version: '0'
100
34
  required_rubygems_version: !ruby/object:Gem::Requirement
101
- none: false
102
35
  requirements:
103
- - - '>='
36
+ - - ">="
104
37
  - !ruby/object:Gem::Version
105
38
  version: '0'
106
39
  requirements: []
107
40
  rubyforge_project:
108
- rubygems_version: 1.8.23
41
+ rubygems_version: 2.2.2
109
42
  signing_key:
110
- specification_version: 3
43
+ specification_version: 4
111
44
  summary: Parses math expressions and returns the result
112
- test_files:
113
- - spec/little_math_pet_spec.rb
114
- - spec/spec_helper.rb
45
+ test_files: []
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
@@ -1 +0,0 @@
1
- 1.9.3-p484
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
-
9
- gem "bundler", "~> 1.0.0"
10
- gem "jeweler", "~> 1.5.2"
11
- gem "rspec", "~> 2.5.0"
12
-
@@ -1,26 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- diff-lcs (1.1.2)
5
- git (1.2.5)
6
- jeweler (1.5.2)
7
- bundler (~> 1.0.0)
8
- git (>= 1.2.5)
9
- rake
10
- rake (0.8.7)
11
- rspec (2.5.0)
12
- rspec-core (~> 2.5.0)
13
- rspec-expectations (~> 2.5.0)
14
- rspec-mocks (~> 2.5.0)
15
- rspec-core (2.5.1)
16
- rspec-expectations (2.5.0)
17
- diff-lcs (~> 1.1.2)
18
- rspec-mocks (2.5.0)
19
-
20
- PLATFORMS
21
- ruby
22
-
23
- DEPENDENCIES
24
- bundler (~> 1.0.0)
25
- jeweler (~> 1.5.2)
26
- rspec (~> 2.5.0)
@@ -1,20 +0,0 @@
1
- Copyright (c) 2011 Kostas Karachalios
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,44 +0,0 @@
1
- = Little math pet
2
-
3
- This is a simple math parser. It always returns in Float.
4
-
5
- 0.1 - Supports addition/subtraction, multiplication/division, exponents and brackets in their correct order.
6
-
7
- 0.2 - Supports percentage calculations.
8
-
9
- == Examples
10
-
11
- Install:
12
- gem install little_math_pet
13
-
14
- Require:
15
- require "little_math_pet"
16
-
17
- Usage:
18
- LittleMathPet.new("5*12+8").calc # => 68.0
19
- LittleMathPet.new("5*(12+8)").calc # => 100.0
20
- LittleMathPet.new("60-20%").calc # => 48.0
21
-
22
- It also can handle variables
23
- LittleMathPet.new("5*a+8").calc(:a => 4) # => 28.0
24
- LittleMathPet.new("a*b+c^d").calc(:a => 4, :b => 3, :c => 2, :d => 5) # => 44.0
25
-
26
- == Syntax
27
-
28
- Mostly ruby (+ - * / ** and ()) but can also accept : for division, ^ for exponents and [] for bracketing. It will also not mind about spaces.
29
-
30
- == Contributing to little-math-pet
31
-
32
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
33
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
34
- * Fork the project
35
- * Start a feature/bugfix branch
36
- * Commit and push until you are happy with your contribution
37
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
38
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
39
-
40
- == Copyright
41
-
42
- Copyright (c) 2011 Kostas Karachalios. See LICENSE.txt for
43
- further details.
44
-
data/Rakefile DELETED
@@ -1,46 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "little_math_pet"
16
- gem.homepage = "http://github.com/vrinek/little-math-pet"
17
- gem.license = "MIT"
18
- gem.summary = %Q{Parses math expressions and returns the result}
19
- gem.description = %Q{LittleMathPet understands simple math expressions in string format with mutliple variables and returns the result of the expression}
20
- gem.email = "kostas.karachalios@me.com"
21
- gem.authors = ["Kostas Karachalios"]
22
- end
23
- Jeweler::RubygemsDotOrgTasks.new
24
-
25
- require 'rake/rdoctask'
26
- Rake::RDocTask.new do |rdoc|
27
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
28
-
29
- rdoc.rdoc_dir = 'rdoc'
30
- rdoc.title = "little-math-pet #{version}"
31
- rdoc.rdoc_files.include('README*')
32
- rdoc.rdoc_files.include('lib/**/*.rb')
33
- end
34
-
35
- require 'rspec/core'
36
- require 'rspec/core/rake_task'
37
- RSpec::Core::RakeTask.new(:spec) do |spec|
38
- spec.pattern = FileList['spec/**/*_spec.rb']
39
- end
40
-
41
- RSpec::Core::RakeTask.new(:rcov) do |spec|
42
- spec.pattern = 'spec/**/*_spec.rb'
43
- spec.rcov = true
44
- end
45
-
46
- task :default => :spec
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.4.0
@@ -1,62 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "little_math_pet"
8
- s.version = "0.4.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Kostas Karachalios"]
12
- s.date = "2015-01-08"
13
- s.description = "LittleMathPet understands simple math expressions in string format with mutliple variables and returns the result of the expression"
14
- s.email = "kostas.karachalios@me.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".ruby-version",
22
- ".travis.yml",
23
- "Gemfile",
24
- "Gemfile.lock",
25
- "LICENSE.txt",
26
- "README.rdoc",
27
- "Rakefile",
28
- "VERSION",
29
- "lib/little_math_pet.rb",
30
- "little_math_pet.gemspec",
31
- "spec/little_math_pet_spec.rb",
32
- "spec/spec_helper.rb"
33
- ]
34
- s.homepage = "http://github.com/vrinek/little-math-pet"
35
- s.licenses = ["MIT"]
36
- s.require_paths = ["lib"]
37
- s.rubygems_version = "1.8.23"
38
- s.summary = "Parses math expressions and returns the result"
39
- s.test_files = [
40
- "spec/little_math_pet_spec.rb",
41
- "spec/spec_helper.rb"
42
- ]
43
-
44
- if s.respond_to? :specification_version then
45
- s.specification_version = 3
46
-
47
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
- s.add_runtime_dependency(%q<bundler>, ["~> 1.0.0"])
49
- s.add_runtime_dependency(%q<jeweler>, ["~> 1.5.2"])
50
- s.add_runtime_dependency(%q<rspec>, ["~> 2.5.0"])
51
- else
52
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
54
- s.add_dependency(%q<rspec>, ["~> 2.5.0"])
55
- end
56
- else
57
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
59
- s.add_dependency(%q<rspec>, ["~> 2.5.0"])
60
- end
61
- end
62
-
@@ -1,198 +0,0 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
-
4
- describe LittleMathPet do
5
- context "when a single number is given" do
6
- equations = {
7
- "8" => 8.0,
8
- "78.65" => 78.65,
9
- "-3.5" => -3.5,
10
- "30%" => 0.3
11
- }
12
-
13
- equations.each do |equation, result|
14
- it "returns that number in float (#{equation} = #{result})" do
15
- LittleMathPet.new(equation).calc.should == result
16
- end
17
- end
18
- end
19
-
20
- context "when a simple equation is given" do
21
- equations = {
22
- "5+3" => 8.0,
23
- "7-5" => 2.0,
24
- "5-7" => -2.0,
25
- "5*3" => 15.0,
26
- "15/5" => 3.0,
27
- "-15/5" => -3.0,
28
- "2^3" => 8.0,
29
- "12+50%" => 18.0,
30
- "120*25%" => 30.0,
31
- "7 / 50%" => 14.0
32
- }
33
-
34
- equations.each do |equation, result|
35
- it "solves the equation (#{equation} = #{result})" do
36
- LittleMathPet.new(equation).calc.should == result
37
- end
38
- end
39
- end
40
-
41
- context "when a more complex equation is given" do
42
- equations = {
43
- "5+3+10" => 18.0,
44
- "7-5-2" => 0.0,
45
- "5-7+6" => 4.0,
46
- "5*3/10" => 1.5,
47
- "15/5*2" => 6.0,
48
- "-15/5*7" => -21.0,
49
- "12+10+50%+20%" => 30,
50
- "-6 * 5" => -30,
51
- "6 * -5" => -30,
52
- "30 / -3" => -10,
53
- "-30 / -3" => 10,
54
- }
55
-
56
- equations.each do |equation, result|
57
- it "solves the equation (#{equation} = #{result})" do
58
- LittleMathPet.new(equation).calc.should == result
59
- end
60
- end
61
-
62
- equations = {
63
- "5*3+10" => 25.0,
64
- "10+3*5" => 25.0,
65
- "5-7/2" => 1.5,
66
- "-8/2^2" => -2.0,
67
- "(5+2)*2" => 14.0,
68
- "(5+2)+50%" => 10.5,
69
- }
70
-
71
- equations.each do |equation, result|
72
- it "respects the proper math order (#{equation} = #{result})" do
73
- LittleMathPet.new(equation).calc.should == equations[equation]
74
- end
75
- end
76
- end
77
-
78
- context "when an equation with multiple parenthesis is given" do
79
- equations = {
80
- "5 - (-3 - (-8 / 2))" => 4.0,
81
- "((7 - 2) * 6) / 2" => 15.0,
82
- }
83
-
84
- equations.each do |equation, result|
85
- it "respects the proper math order (#{equation} = #{result})" do
86
- LittleMathPet.new(equation).calc.should == equations[equation]
87
- end
88
- end
89
- end
90
-
91
- context "when a different grammar is used for the equation" do
92
- equations = {
93
- "5*3:10" => 1.5,
94
- "-8/2**2" => -2.0,
95
- "5 + 7" => 12.0,
96
- "[5+2] : 2" => 3.5,
97
- "100 + 40 %" => 140,
98
- "12 ÷ 4 + 5" => 8,
99
- "2 × 8 - 7" => 9,
100
- "2 × [8 - 7]" => 2,
101
- }
102
-
103
- equations.each do |equation, result|
104
- it "solves the equation (#{equation} = #{result})" do
105
- LittleMathPet.new(equation).calc.should == result
106
- end
107
- end
108
- end
109
-
110
- context "when using curly brackets" do
111
- equations = {
112
- "{5*3}:10" => 1.5,
113
- "-8/{2**2}" => -2.0,
114
- }
115
-
116
- equations.each do |equation, result|
117
- it "solves the equation (#{equation} = #{result})" do
118
- LittleMathPet.new(equation).calc.should == result
119
- end
120
- end
121
- end
122
-
123
- context "when something unknown is given as math" do
124
- equations = [
125
- "five * 5",
126
- "something else",
127
- "+*+"
128
- ]
129
-
130
- equations.each do |equation|
131
- it "raises an exception (#{equation.inspect})" do
132
- begin
133
- LittleMathPet.new(equation).calc
134
- true.should == false
135
- rescue => e
136
- e.message.should =~ /Invalid math expression/
137
- end
138
- end
139
- end
140
- end
141
-
142
- context "when a variable is given (x => 3)" do
143
- value = '3'
144
- equations = {
145
- "5+x+10" => 18.0,
146
- "7-5-x" => -1.0,
147
- "5*x/10" => 1.5,
148
- "15/5*x" => 9.0,
149
- "10+x*5" => 25.0,
150
- "x-7/2" => -0.5,
151
- "-9/x^2" => -1.0,
152
- "x*(2+3)/2" => 7.5
153
- }
154
-
155
- equations.each do |equation, result|
156
- it "uses it in place of x (#{equation} = #{result})" do
157
- LittleMathPet.new(equation).calc(:x => value).should == result
158
- end
159
- end
160
- end
161
-
162
- context "when multiple variables are given (a => 2, b => 5)" do
163
- values = {:a => 2, :b => 5}
164
- equations = {
165
- "5+a+10/b" => 9.0,
166
- "7-5-a*b" => -8.0,
167
- "5^a/10/b" => 0.5,
168
- "b*(a+3)/2" => 12.5
169
- }
170
-
171
- equations.each do |equation, result|
172
- it "uses them in place of the variables (#{equation} = #{result})" do
173
- LittleMathPet.new(equation).calc(values).should == result
174
- end
175
- end
176
- end
177
-
178
- context "when some variables are missing" do
179
- values = {:a => 2, :b => 5}
180
- equations = [
181
- "5+a+10/x",
182
- "7-5-a*y",
183
- "c^a/10/b",
184
- "v*(e+3)/2"
185
- ]
186
-
187
- equations.each do |equation, result|
188
- it "raises an exception (#{equation.inspect})" do
189
- begin
190
- LittleMathPet.new(equation).calc.should == result
191
- true.should == false
192
- rescue => e
193
- e.message.should == 'Invalid math expression'
194
- end
195
- end
196
- end
197
- end
198
- end
@@ -1,9 +0,0 @@
1
- require 'rspec'
2
-
3
- require File.expand_path('../../lib/little_math_pet.rb', __FILE__)
4
-
5
- # Requires supporting files with custom matchers and macros, etc,
6
- # in ./support/ and its subdirectories.
7
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
-
9
- RSpec.configure do |config|; end