Class: FiltrosPersonalizados::FieldsPadroes::Idade

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

Constant Summary

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



5
6
7
# File 'lib/filtros_personalizados/fields_padroes/idade.rb', line 5

def acoes_disponiveis
  ["Igual a", "Diferente de", "Entre", "Nenhum", "Todos"]
end

#fileObject



21
22
23
# File 'lib/filtros_personalizados/fields_padroes/idade.rb', line 21

def file
  'personalizaveis/integer'
end

#selecaoObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/filtros_personalizados/fields_padroes/idade.rb', line 25

def selecao
  self.values.present? ? "selecao Idade " : ""
  if self.values.present?
    case self.tipo_selecionado
    when "Igual a"       then "Idade: #{values.first} anos"
    when "Diferente de"  then "Idade: diferente de #{values.first} anos"
    when "Entre"         then "Idade: #{values.first} até #{values.last} anos"
    else ""
    end
  end
end

#whereObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/filtros_personalizados/fields_padroes/idade.rb', line 9

def where
  return "" if values.blank?
  case self.tipo_selecionado
  when "Igual a"       then "idade_a(pacientes.data_nascimento, interns.data_entrada) == #{values.first}"
  when "Diferente de"  then "idade_a(pacientes.data_nascimento, interns.data_entrada) <> #{values.first}"
  when "Entre"         then "idade_a(pacientes.data_nascimento, interns.data_entrada) between #{values.first} and #{values.last}"
  when "Nenhum"        then "idade_a(pacientes.data_nascimento, interns.data_entrada)  isnull "
  when "Todos"         then "idade_a(pacientes.data_nascimento, interns.data_entrada) notnull "
  else ""
  end
end