Class: MetadataPresenter::Operator

Inherits:
Object
  • Object
show all
Defined in:
app/operators/metadata_presenter/operator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator) ⇒ Operator

Returns a new instance of Operator.



8
9
10
# File 'app/operators/metadata_presenter/operator.rb', line 8

def initialize(operator)
  @operator = operator
end

Instance Attribute Details

#operatorObject (readonly)

Returns the value of attribute operator.



6
7
8
# File 'app/operators/metadata_presenter/operator.rb', line 6

def operator
  @operator
end

Instance Method Details

#evaluate(actual, expected) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/operators/metadata_presenter/operator.rb', line 12

def evaluate(actual, expected)
  operator = klass.constantize.new(actual, expected)

  if expected.is_a?(Array)
    operator.evaluate_collection?
  else
    operator.evaluate?
  end
rescue NameError
  raise NoOperator,
        "Operator '#{operator}' is not implemented. You need to create the class #{klass}"
end

#klassObject



25
26
27
# File 'app/operators/metadata_presenter/operator.rb', line 25

def klass
  "MetadataPresenter::#{@operator.capitalize.classify}Operator"
end