Class: SdbDal::AttributeRange

Inherits:
Object
  • Object
show all
Defined in:
lib/sdb_dal/attribute_range.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AttributeRange

Returns a new instance of AttributeRange.



10
11
12
13
14
15
16
17
18
19
# File 'lib/sdb_dal/attribute_range.rb', line 10

def initialize(options)
    
  self.attribute_description=options[:attribute_description]
    
  self.less_than=options[:less_than]
  self.greater_than=options[:greater_than]
  self.less_than_or_equal_to=options[:less_than_or_equal_to]
  self.greater_than_or_equal_to=options[:greater_than_or_equal_to]
  
end

Instance Attribute Details

#attribute_descriptionObject

if this exists we act on objects else we act on attributes



8
9
10
# File 'lib/sdb_dal/attribute_range.rb', line 8

def attribute_description
  @attribute_description
end

#greater_thanObject

Returns the value of attribute greater_than.



5
6
7
# File 'lib/sdb_dal/attribute_range.rb', line 5

def greater_than
  @greater_than
end

#greater_than_or_equal_toObject

Returns the value of attribute greater_than_or_equal_to.



7
8
9
# File 'lib/sdb_dal/attribute_range.rb', line 7

def greater_than_or_equal_to
  @greater_than_or_equal_to
end

#less_thanObject

Returns the value of attribute less_than.



4
5
6
# File 'lib/sdb_dal/attribute_range.rb', line 4

def less_than
  @less_than
end

#less_than_or_equal_toObject

Returns the value of attribute less_than_or_equal_to.



6
7
8
# File 'lib/sdb_dal/attribute_range.rb', line 6

def less_than_or_equal_to
  @less_than_or_equal_to
end

Instance Method Details

#matches?(arg) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sdb_dal/attribute_range.rb', line 20

def matches?(arg)
  value=arg
  if self.attribute_description
    #its an object so pull out the value
    value=arg[attribute_description.name]
  end
  return false if value==nil
  return false if self.less_than                && (value <=> self.less_than)               >-1
  return false if self.less_than_or_equal_to    && (value <=> self.less_than_or_equal_to)   ==1
  return false if self.greater_than             && (value<=>self.greater_than)              <1
  return false if self.greater_than_or_equal_to &&(value<=>self.greater_than_or_equal_to)   ==-1
  
  return true
end

#to_sdb_queryObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sdb_dal/attribute_range.rb', line 34

def to_sdb_query
  query=''
  if self.less_than 
    query << "  '#{attribute_description.name}' < '#{ attribute_description.format_for_sdb( self.less_than)}'"
  end
  if self.greater_than  
    query << ' and ' if query.length>0
    query << "  '#{attribute_description.name}' > '#{ attribute_description.format_for_sdb( self.greater_than)}'"
  end
  if  self.less_than_or_equal_to 
    query << ' and ' if query.length>0
    query << "  '#{attribute_description.name}' <= '#{ attribute_description.format_for_sdb( self.less_than_or_equal_to)}'"
  end
  if  self.greater_than_or_equal_to 
    query << ' and ' if query.length>0
    query << "  '#{attribute_description.name}' >= '#{ attribute_description.format_for_sdb( self.greater_than_or_equal_to)}'"
  end
           
  return  query
end