Class: Nelson::ExpressionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/nelson/expression_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*terms) ⇒ ExpressionBuilder

Returns a new instance of ExpressionBuilder.

Raises:

  • (ArgumentError)


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

#termsObject

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_termsObject



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