Class: FiltrosPersonalizados::Association
- Inherits:
-
Object
- Object
- FiltrosPersonalizados::Association
- Defined in:
- lib/filtros_personalizados/association.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#relation ⇒ Object
Returns the value of attribute relation.
-
#search ⇒ Object
Returns the value of attribute search.
Instance Method Summary collapse
-
#initialize(relation, name, search) ⇒ Association
constructor
A new instance of Association.
- #to_h(values = []) ⇒ Object
- #to_i(values) ⇒ Object
- #to_selecao(values = []) ⇒ Object
Constructor Details
#initialize(relation, name, search) ⇒ Association
Returns a new instance of Association.
4 5 6 7 8 |
# File 'lib/filtros_personalizados/association.rb', line 4 def initialize relation, name, search self.relation = relation self.name = name self.search = search end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/filtros_personalizados/association.rb', line 2 def name @name end |
#relation ⇒ Object
Returns the value of attribute relation.
2 3 4 |
# File 'lib/filtros_personalizados/association.rb', line 2 def relation @relation end |
#search ⇒ Object
Returns the value of attribute search.
2 3 4 |
# File 'lib/filtros_personalizados/association.rb', line 2 def search @search end |
Instance Method Details
#to_h(values = []) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/filtros_personalizados/association.rb', line 10 def to_h(values=[]) lista = [] if values.present? self.relation.pluralize.classify.constantize.where("#{self.search} in (?)", values.first.split(',') + [-1]).each do |r| lista << {id: r.send(self.search), text: r.send(self.name)} end end lista end |
#to_i(values) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/filtros_personalizados/association.rb', line 30 def to_i(values) lista = [] if values.present? self.relation.pluralize.classify.constantize.where("#{self.search} in (?)", values.first.split(',')).each do |r| lista << r.send(self.search) end end lista.join(", ") end |
#to_selecao(values = []) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/filtros_personalizados/association.rb', line 20 def to_selecao(values = []) lista = [] if values.present? self.relation.pluralize.classify.constantize.where("#{self.search} in (?)", values.first.split(',') + [-1]).each do |r| lista << r.send(self.name) end end lista.join(", ") end |