Class: Repository::Criterion
- Inherits:
-
Object
- Object
- Repository::Criterion
show all
- Defined in:
- lib/repository/criterion.rb
Defined Under Namespace
Classes: And, Conjunction, Contains, Equals, Factory, Join, Key, Or
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ Criterion
Returns a new instance of Criterion.
6
7
8
9
10
11
12
|
# File 'lib/repository/criterion.rb', line 6
def initialize(options)
@subject = (options[:subject] || "id").to_s
@descriptor = options[:descriptor] || "#{@subject} #{default_descriptor}"
@value = options[:value]
@value = nil if @value.blank?
@property_name = options[:property_name] || @subject
end
|
Instance Attribute Details
#descriptor ⇒ Object
Returns the value of attribute descriptor.
4
5
6
|
# File 'lib/repository/criterion.rb', line 4
def descriptor
@descriptor
end
|
#property_name ⇒ Object
Returns the value of attribute property_name.
4
5
6
|
# File 'lib/repository/criterion.rb', line 4
def property_name
@property_name
end
|
#subject ⇒ Object
Returns the value of attribute subject.
4
5
6
|
# File 'lib/repository/criterion.rb', line 4
def subject
@subject
end
|
#value ⇒ Object
Returns the value of attribute value.
4
5
6
|
# File 'lib/repository/criterion.rb', line 4
def value
@value
end
|
Instance Method Details
#+(other) ⇒ Object
Also known as:
&
49
50
51
|
# File 'lib/repository/criterion.rb', line 49
def +(other)
And.new(self, other)
end
|
#==(other) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/repository/criterion.rb', line 14
def ==(other)
self.class == other.class &&
self.subject == other.subject &&
self.descriptor == other.descriptor &&
self.value == other.value &&
self.property_name == other.property_name
end
|
#default_descriptor ⇒ Object
26
27
28
|
# File 'lib/repository/criterion.rb', line 26
def default_descriptor
self.class.name.gsub(/[A-Z]/, " \\0").gsub(/.*::/, '').downcase.strip
end
|
#described_value ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/repository/criterion.rb', line 30
def described_value
if value.blank?
"any"
elsif value == 0
"none"
else
value
end
end
|
#description ⇒ Object
22
23
24
|
# File 'lib/repository/criterion.rb', line 22
def description
"#{descriptor} #{described_value}"
end
|
#find_in(storage) ⇒ Object
59
60
61
|
# File 'lib/repository/criterion.rb', line 59
def find_in(storage)
storage.find(self)
end
|
#match?(object) ⇒ Boolean
40
41
42
43
44
45
46
47
|
# File 'lib/repository/criterion.rb', line 40
def match?(object)
object_value = object.send(property_name)
if value.is_a? Array
value.detect{|criterion_value| match_value?(criterion_value, object_value)}
else
match_value?(value, object_value)
end
end
|
#|(other) ⇒ Object
55
56
57
|
# File 'lib/repository/criterion.rb', line 55
def |(other)
Or.new(self, other)
end
|