Class: Edgarj::SearchPopup

Inherits:
Search
  • Object
show all
Defined in:
app/models/edgarj/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

#persisted?

Constructor Details

#initialize(klass, hash = nil) ⇒ SearchPopup

Returns a new instance of SearchPopup.



9
10
11
12
13
# File 'app/models/edgarj/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

#colObject

Returns the value of attribute col.



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

def col
  @col
end

#klass_strObject

Returns the value of attribute klass_str.



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

def klass_str
  @klass_str
end

#valObject

Returns the value of attribute val.



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

def val
  @val
end

Instance Method Details

#conditionsObject

implement to generate search-conditions



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/edgarj/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