Class: FiltrosPersonalizados::FieldsPadroes::String

Inherits:
Field
  • Object
show all
Defined in:
lib/filtros_personalizados/fields_padroes/string.rb

Constant Summary collapse

NAO_CONTEM =
"Não Contém"
CONTEM =
"Contém"

Constants inherited from Field

Field::DIFERENTE, Field::ENTRE, Field::IGUAL, Field::MAIOR_QUE, Field::MENOR_QUE, Field::NENHUM, Field::TODOS

Instance Attribute Summary

Attributes inherited from Field

#association, #autocomplete_path, #collection, #collection_id, #collection_name, #field_name, #field_type, #is_open, #noactions, #options, #partial_name, #relation, #tipo_selecionado, #values

Instance Method Summary collapse

Methods inherited from Field

#caption, #initialize

Constructor Details

This class inherits a constructor from FiltrosPersonalizados::FieldsPadroes::Field

Instance Method Details

#acoes_disponiveisObject

Personalizaveis::Integer.new(‘convenio_id’, relation: ‘interns’, tipo_selecionado: ‘Entre’, values: [3, 5])



10
11
12
# File 'lib/filtros_personalizados/fields_padroes/string.rb', line 10

def acoes_disponiveis
  [CONTEM, NAO_CONTEM, IGUAL, DIFERENTE, TODOS] - self.noactions
end

#fileObject



24
25
26
# File 'lib/filtros_personalizados/fields_padroes/string.rb', line 24

def file
  "personalizaveis/#{ self.partial_name || 'string'}.html.erb"
end

#selecaoObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/filtros_personalizados/fields_padroes/string.rb', line 28

def selecao
  aux = case self.tipo_selecionado
    when IGUAL       then self.values.present? ? " #{IGUAL.downcase} #{self.values.first}" : ""
    when DIFERENTE   then self.values.present? ? " #{DIFERENTE.downcase} #{self.values.first}" : ""
    when CONTEM      then self.values.present? ? " #{CONTEM.downcase} #{values.first}" : ""
    when NAO_CONTEM  then self.values.present? ? " #{NAO_CONTEM.downcase} #{values.first}" : ""
    when TODOS       then TODOS.downcase
    else ""
  end
  aux.present? ? "#{self.caption}: #{aux}" : ""
end

#whereObject



14
15
16
17
18
19
20
21
22
# File 'lib/filtros_personalizados/fields_padroes/string.rb', line 14

def where
  case self.tipo_selecionado
  when CONTEM      then values.first.present? ? "#{self.relation}.#{self.field_name} ilike '%#{values.first}%'"     : ""
  when NAO_CONTEM  then values.first.present? ? "#{self.relation}.#{self.field_name} not ilike '%#{values.first}%'" : ""
  when IGUAL       then values.first.present? ? "#{self.relation}.#{self.field_name} == '#{values.first}'"          : ""
  when DIFERENTE   then values.first.present? ? "#{self.relation}.#{self.field_name} <> '#{values.first}'"          : ""
  else ""
  end
end