Class: Predicator::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/predicator/variable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, attribute) ⇒ Variable

Returns a new instance of Variable.



5
6
7
8
# File 'lib/predicator/variable.rb', line 5

def initialize model, attribute
  @model = model
  @attribute = attribute
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



3
4
5
# File 'lib/predicator/variable.rb', line 3

def attribute
  @attribute
end

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'lib/predicator/variable.rb', line 3

def model
  @model
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
23
24
# File 'lib/predicator/variable.rb', line 20

def == other
  other.kind_of?(self.class) &&
    other.model == model &&
    other.attribute == attribute
end

#value_in(context) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/predicator/variable.rb', line 10

def value_in context
  entity_name = model.to_s
  entity = context.bindings[entity_name]
  if entity.nil?
    raise ArgumentError, "Unknown entity #{entity_name}"
  else
    entity.send attribute
  end
end