Class: Nelson::ExpressionBuilder
- Inherits:
-
Object
- Object
- Nelson::ExpressionBuilder
- Defined in:
- lib/nelson/expression_builder.rb
Direct Known Subclasses
AdditionExpressionBuilder, DivisionExpressionBuilder, MultipicationExpressionBuilder, SubtractionExpressionBuilder
Instance Attribute Summary collapse
-
#terms ⇒ Object
Returns the value of attribute terms.
Instance Method Summary collapse
- #and(term) ⇒ Object
- #built_terms ⇒ Object
- #divided_by(term) ⇒ Object
-
#initialize(*terms) ⇒ ExpressionBuilder
constructor
A new instance of ExpressionBuilder.
- #minus(term) ⇒ Object
- #plus(term) ⇒ Object
- #times(term) ⇒ Object
Constructor Details
#initialize(*terms) ⇒ ExpressionBuilder
Returns a new instance of ExpressionBuilder.
6 7 8 9 |
# File 'lib/nelson/expression_builder.rb', line 6 def initialize(*terms) raise ArgumentError, "At least 1 term must be specified" unless terms.length > 0 @terms = terms end |
Instance Attribute Details
#terms ⇒ Object
Returns the value of attribute terms.
4 5 6 |
# File 'lib/nelson/expression_builder.rb', line 4 def terms @terms end |
Instance Method Details
#and(term) ⇒ Object
11 12 13 14 |
# File 'lib/nelson/expression_builder.rb', line 11 def and(term) terms << term return self end |
#built_terms ⇒ Object
32 33 34 |
# File 'lib/nelson/expression_builder.rb', line 32 def built_terms terms.map { |e| e.is_a?(ExpressionBuilder) ? e.build : e } end |
#divided_by(term) ⇒ Object
28 29 30 |
# File 'lib/nelson/expression_builder.rb', line 28 def divided_by(term) DivisionExpressionBuilder.new(self, term) end |
#minus(term) ⇒ Object
24 25 26 |
# File 'lib/nelson/expression_builder.rb', line 24 def minus(term) SubtractionExpressionBuilder.new(self, term) end |
#plus(term) ⇒ Object
20 21 22 |
# File 'lib/nelson/expression_builder.rb', line 20 def plus(term) AdditionExpressionBuilder.new(self, term) end |
#times(term) ⇒ Object
16 17 18 |
# File 'lib/nelson/expression_builder.rb', line 16 def times(term) MultipicationExpressionBuilder.new(self, term) end |