arithmetic 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTFkMzQwNDk4YWVkZTk1NWY2NTA4M2Y3MTUyODc5ZTg5MWZkOTE2MA==
4
+ NzVjMzE4ZDlmZGEzNGY5MDQ4Y2M4NGNmODk3NWI3OWQ5NDk5MGY1MA==
5
5
  data.tar.gz: !binary |-
6
- Yzg1NTkyYmNiOTUzYzQ4ZTQyYTg0ODZlZTI5NzEwNGViZWRhODA4ZA==
6
+ OGYxMjYyNGZmOTc4ZThhN2U0ZmZkMDk3ODAwNzY5N2QwNWZjMWVmYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDY3YTA4ZmE4Yzc1MzA5YjQxZDI5N2ZiYWNhMmNmYTZhZWUxOTI0NDgwYmE2
10
- NjhmYjVmYWJmNWJkYjQ5Mjk0NGU5MzY1NWJkOTNjNWM1ODNkNDZmZDI0ODgy
11
- OGRhMjFmNjY2YjNkZGM0NTQzZmY2ZGJiM2U3ODcyYjg1MTg3Y2M=
9
+ MDhjNGZiZjlmZDY4MTA5MWQyYTRmMWZmOTdlZGQzNmRkOTM0ZWUwNmFlNzBl
10
+ NmUxYjAzYTc4Y2ZiYzlhMzdiMTZhMDFlMDRiNTY5NmJiYTVmNjM4MjlhMmY3
11
+ ODY4ZjJkMDhhNmFkMzkwNDkwY2QzMmM5ODZiYWU3ZDFmMWUwMjM=
12
12
  data.tar.gz: !binary |-
13
- YTQ4M2FmYTJhYTkxZWU2ODYxOTI3ZjIxNzhjZjAwNjEyNGQwY2NiMDAzNDE0
14
- OGRiNDdkOGUxZDg3NzQwNmU3OGU5NTNiYjAxOThkOTE5MmMzNzVhMjk0ZDVl
15
- MGEwOTEzNzljM2Y2OTE1Y2EwOTlmYTk1MDgzMjFlN2VhNjhjMWI=
13
+ OGIzOGJiNDM2ZmQ4YTVhMDVjMWE1ZjMxNGI0MjY1MjI1MTgyYTI0NjJmZGY0
14
+ MWU1ODIyOWI5MmVkOTcwYTQxNTBmZDQxZWExZjcxMjNkNjAzNzc4NDQzMDJh
15
+ ZTQyZjA0OTViYjZiZTllZTNmZGU3OGE1NjZkNjkxYjQwZWY4ZTU=
data/.gitignore CHANGED
@@ -11,6 +11,7 @@ spec/reports
11
11
  test/tmp
12
12
  test/version_tmp
13
13
  tmp
14
+ .rake_tasks
14
15
 
15
16
  # YARD artifacts
16
17
  .yardoc
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arithmetic (0.1.1)
4
+ arithmetic (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -10,7 +10,7 @@ module Arithmetic
10
10
  Expression.new(Parser.new(expression).parse)
11
11
  end
12
12
 
13
- def self.is_operand?(token)
14
- !token.is_a?(Arithmetic::Operator) && token != "(" && token != ")"
13
+ def self.is_a_number?(token)
14
+ Arithmetic::Parser.is_a_number?(token)
15
15
  end
16
16
  end
@@ -1,5 +1,10 @@
1
1
  module Arithmetic
2
2
  class Parser
3
+
4
+ def self.is_a_number?(str)
5
+ str.respond_to?(:to_str) && !!str.to_str.match(/^[\d\.]+$/)
6
+ end
7
+
3
8
  def initialize(exp)
4
9
  @expression = exp.to_s
5
10
  @node_stack = []
@@ -45,7 +50,7 @@ module Arithmetic
45
50
  private
46
51
 
47
52
  def push_operand(operand)
48
- raise InvalidExpression.new(@expression) unless is_a_number?(operand)
53
+ raise InvalidExpression.new(@expression) unless Arithmetic::Parser.is_a_number?(operand)
49
54
  @node_stack.push(OperandNode.new(operand))
50
55
  end
51
56
 
@@ -60,10 +65,6 @@ module Arithmetic
60
65
 
61
66
  @node_stack.push(OperatorNode.new(operator, operands))
62
67
  end
63
-
64
- def is_a_number?(str)
65
- !!str.match(/^[\d\.]+$/)
66
- end
67
68
  end
68
69
 
69
70
  class Tokenizer
@@ -1,3 +1,3 @@
1
1
  module Arithmetic
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -96,6 +96,20 @@ describe Arithmetic do
96
96
  end
97
97
  end
98
98
 
99
+ describe ".is_a_number?" do
100
+ it "returns true if argument is a number" do
101
+ expect(Arithmetic.is_a_number?('23.5')).to eq(true)
102
+ end
103
+
104
+ it "returns false if argument is not a number" do
105
+ expect(Arithmetic.is_a_number?('2aa23')).to eq(false)
106
+ end
107
+
108
+ it "returns false if argument is not convertible to string" do
109
+ expect(Arithmetic.is_a_number?(Object.new)).to eq(false)
110
+ end
111
+ end
112
+
99
113
  def exp_should_error(exp)
100
114
  expect {test_init exp}.to raise_error Arithmetic::InvalidExpression
101
115
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arithmetic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Kirby