nelson 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82ec4b93c37ae50aef8150c90dd14f1e959dca31
4
- data.tar.gz: 443e8a03fb69dd634d459ce7e97cfcfd8c3e7ce3
3
+ metadata.gz: ea222574d0c1f96899947a726b098e6b05db0e9b
4
+ data.tar.gz: 831e22c0b25c4e5e996b64f82ca51306193122df
5
5
  SHA512:
6
- metadata.gz: c05a5f614bf7788d3d71827af5bfc228b958e2ec1852d992022526da4ec5961520a9f33ac9b511da72c0462b9078af7e0d966423fd67318cbaff053159e321c3
7
- data.tar.gz: 2060d09305d3dbbed963028e6ea063853a944a90ff4fa44aa8f39d76bd190bfe0cd5454b9377b08e526f1ea938adae231fd20d98760905e9c81cecdbd6196fbf
6
+ metadata.gz: c31c1761617ee24438e91e79a345d5029d3effe47a0c9b586d94888ce91f15aec52ed6aec4ecf5e1b24b205b9a4aa31a803aa19bd8e9d89831f052149f778e3c
7
+ data.tar.gz: f9d3c756a80fd006024b21b4f12dd26a375315bf6d136075b8877998548ac227bf8fb46c6db640a6cee18430ce81b11cd8bc78a0e8e7175d0113589aed9a78d5
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Nelson
2
2
  [![Gem Version](https://badge.fury.io/rb/nelson.svg)](http://badge.fury.io/rb/nelson)
3
+ [![Build Status](https://travis-ci.org/pducks32/nelson.svg)](https://travis-ci.org/pducks32/nelson)
3
4
 
4
5
  A library for building, manipulating, displaying, and solving math expressions using a fluent API.
5
6
 
@@ -20,6 +20,12 @@ module Nelson
20
20
  AdditionExpression.new(rhs_value, lhs_value).call
21
21
  end
22
22
 
23
+ def -(term)
24
+ rhs_value = self.call
25
+ lhs_value = try_to_eval term
26
+ SubtractionExpression.new(rhs_value, lhs_value).call
27
+ end
28
+
23
29
  private
24
30
 
25
31
  def try_to_eval(term)
@@ -29,4 +35,5 @@ module Nelson
29
35
 
30
36
  autoload :MultipicationExpression, "nelson/expressions/multipication_expression"
31
37
  autoload :AdditionExpression, "nelson/expressions/addition_expression"
38
+ autoload :SubtractionExpression, "nelson/expressions/subtraction_expression"
32
39
  end
@@ -20,8 +20,13 @@ module Nelson
20
20
  def plus(term)
21
21
  AdditionExpressionBuilder.new(self, term)
22
22
  end
23
+
24
+ def minus(term)
25
+ SubtractionExpressionBuilder.new(self, term)
26
+ end
23
27
  end
24
28
 
25
29
  autoload :MultipicationExpressionBuilder, "nelson/expression_builders/multipication_expression_builder"
26
30
  autoload :AdditionExpressionBuilder, "nelson/expression_builders/addition_expression_builder"
31
+ autoload :SubtractionExpressionBuilder, "nelson/expressions/subtraction_expression_builder"
27
32
  end
@@ -0,0 +1,9 @@
1
+
2
+ module Nelson
3
+ class SubtractionExpressionBuilder < ExpressionBuilder
4
+ def build
5
+ terms.map! { |e| e.is_a?(ExpressionBuilder) ? e.build : e }
6
+ SubtractionExpression.new(*terms)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module Nelson
3
+ class SubtractionExpression < Expression
4
+ def call
5
+ terms.reduce(:-)
6
+ end
7
+
8
+
9
+ def to_s
10
+ terms.map do |t|
11
+ t.is_a?(Expression) ? "(#{t})" : t
12
+ end.join("-")
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Nelson
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nelson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Metcalfe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-28 00:00:00.000000000 Z
11
+ date: 2015-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -118,8 +118,10 @@ files:
118
118
  - lib/nelson/expression_builder.rb
119
119
  - lib/nelson/expression_builders/addition_expression_builder.rb
120
120
  - lib/nelson/expression_builders/multipication_expression_builder.rb
121
+ - lib/nelson/expression_builders/subtraction_expression_builder.rb
121
122
  - lib/nelson/expressions/addition_expression.rb
122
123
  - lib/nelson/expressions/multipication_expression.rb
124
+ - lib/nelson/expressions/subtraction_expression.rb
123
125
  - lib/nelson/version.rb
124
126
  - nelson.gemspec
125
127
  homepage: