Class: Repository::Criterion::Key

Inherits:
Equals show all
Defined in:
lib/repository/criterion.rb

Instance Attribute Summary

Attributes inherited from Repository::Criterion

#descriptor, #property_name, #subject, #value

Instance Method Summary collapse

Methods inherited from Equals

#value

Methods inherited from Repository::Criterion

#+, #==, #default_descriptor, #described_value, #description, #find_in, #|

Constructor Details

#initialize(options) ⇒ Key

Returns a new instance of Key.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/repository/criterion.rb', line 109

def initialize(options)
  options[:value] = case options[:value]
  when Fixnum
    [options[:value]]
  when String
    [options[:value].to_i]
  when Array
    options[:value].map{|v|v.to_i} # todo: allow arrays of Criteria too
  else
    options[:value]
  end
  options[:descriptor] ||= "#"
  super(options)
end

Instance Method Details

#match?(object) ⇒ Boolean

Returns:

  • (Boolean)


124
125
126
127
# File 'lib/repository/criterion.rb', line 124

def match?(object)
  object_value = object.send(property_name)
  value.detect{|criterion_value| match_value?(criterion_value, object_value)} || false
end

#match_value?(criterion_value, object_value) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/repository/criterion.rb', line 129

def match_value?(criterion_value, object_value)
  object_value == criterion_value
end