Class: Edgar::SearchPopup

Inherits:
Search
  • Object
show all
Defined in:
app/models/edgar/search_popup.rb

Overview

Search condition for popup

Instance Attribute Summary (collapse)

Attributes inherited from Search

#_klass_str, #errors

Instance Method Summary (collapse)

Methods inherited from Search

#column_type, #persisted?

Constructor Details

- (SearchPopup) initialize(klass, hash = nil)

A new instance of SearchPopup



9
10
11
12
13
# File 'app/models/edgar/search_popup.rb', line 9

def initialize(klass, hash = nil)
  super(klass)
  @col  = hash ? hash[:col] : nil
  @val  = hash ? hash[:val] : nil
end

Instance Attribute Details

- (Object) col

Returns the value of attribute col



4
5
6
# File 'app/models/edgar/search_popup.rb', line 4

def col
  @col
end

- (Object) klass_str

Returns the value of attribute klass_str



4
5
6
# File 'app/models/edgar/search_popup.rb', line 4

def klass_str
  @klass_str
end

- (Object) val

Returns the value of attribute val



4
5
6
# File 'app/models/edgar/search_popup.rb', line 4

def val
  @val
end

Instance Method Details

- (Object) conditions

implement to generate search-conditions



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/edgar/search_popup.rb', line 16

def conditions
  return ['1=0'] if !valid?

  if @val.blank?
    []
  else
    # FIXME: assume type is just string
    op  = '=?'
    val = @val
    if val =~ /\*$/
      op  = ' like ?'
      val = @val.gsub(/\*/, '%')
    end
    ["#{@col}#{op}", val]
  end
end

- (Object) validate_integer (private)



34
35
36
37
38
39
40
41
42
# File 'app/models/edgar/search_popup.rb', line 34

def validate_integer
  case column_type(col)
  when :integer
    if val.present? && val !~ /^[\d\.\-]+$/
      errors.add(:val, :not_an_integer)
    end
  else
  end
end