Class: Repository::Criterion::Key
- Inherits:
-
Equals
- Object
- Repository::Criterion
- Equals
- Repository::Criterion::Key
- Defined in:
- lib/repository/criterion.rb
Instance Attribute Summary
Attributes inherited from Repository::Criterion
#descriptor, #property_name, #subject, #value
Instance Method Summary collapse
-
#initialize(options) ⇒ Key
constructor
A new instance of Key.
- #match?(object) ⇒ Boolean
- #match_value?(criterion_value, object_value) ⇒ Boolean
Methods inherited from Equals
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() [:value] = case [:value] when Fixnum [[:value]] when String [[:value].to_i] when Array [:value].map{|v|v.to_i} # todo: allow arrays of Criteria too else [:value] end [:descriptor] ||= "#" super() end |
Instance Method Details
#match?(object) ⇒ 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
129 130 131 |
# File 'lib/repository/criterion.rb', line 129 def match_value?(criterion_value, object_value) object_value == criterion_value end |