Class: Given::BinaryOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/given/binary_operation.rb

Constant Summary collapse

BINARY_EXPLAINATIONS =
{
  :==  => "to equal",
  :!=  => "to not equal",
  :<   => "to be less than",
  :<=  => "to be less or equal to",
  :>   => "to be greater than",
  :>=  => "to be greater or equal to",
  :=~  => "to match",
  :!~  => "to not match",
  :=== => "to be matched by",
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, operator, right) ⇒ BinaryOperation

Returns a new instance of BinaryOperation.



18
19
20
21
22
# File 'lib/given/binary_operation.rb', line 18

def initialize(left, operator, right)
  @left = left
  @operator = operator
  @right = right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



16
17
18
# File 'lib/given/binary_operation.rb', line 16

def left
  @left
end

#operatorObject (readonly)

Returns the value of attribute operator.



16
17
18
# File 'lib/given/binary_operation.rb', line 16

def operator
  @operator
end

#rightObject (readonly)

Returns the value of attribute right.



16
17
18
# File 'lib/given/binary_operation.rb', line 16

def right
  @right
end

Class Method Details

.parse(sexp) ⇒ Object



28
29
30
31
# File 'lib/given/binary_operation.rb', line 28

def self.parse(sexp)
  return nil unless sexp.first == :binary
  new(sexp[1], sexp[2], sexp[3])
end

Instance Method Details

#explainObject



24
25
26
# File 'lib/given/binary_operation.rb', line 24

def explain
  BINARY_EXPLAINATIONS[operator]
end