Class: ApplicationsFilter
- Inherits:
-
Object
- Object
- ApplicationsFilter
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Serialization
- Defined in:
- app/controllers/applications_controller.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
-
#type_options ⇒ Object
Returns the value of attribute type_options.
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #apply(applications) ⇒ Object
-
#initialize(attributes = {}) ⇒ ApplicationsFilter
constructor
A new instance of ApplicationsFilter.
- #persisted? ⇒ Boolean
- #present? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ ApplicationsFilter
Returns a new instance of ApplicationsFilter.
9 10 11 |
# File 'app/controllers/applications_controller.rb', line 9 def initialize(attributes={}) attributes.each { |key,value| send("#{key}=", value) } unless attributes.nil? end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'app/controllers/applications_controller.rb', line 8 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'app/controllers/applications_controller.rb', line 8 def type @type end |
#type_options ⇒ Object
Returns the value of attribute type_options.
8 9 10 |
# File 'app/controllers/applications_controller.rb', line 8 def @type_options end |
Class Method Details
.wildcard_match?(search_str, value) ⇒ Boolean
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/applications_controller.rb', line 42 def self.wildcard_match?(search_str, value) return true if search_str.nil? || search_str.blank? if !(search_str =~ /\*/) search_str = "*" + search_str + "*" end # make the regexp safe wildcard_parse = search_str.split('*') wildcard_re = "" for element in wildcard_parse if element == "" wildcard_re += ".*" else wildcard_re += Regexp.escape(element) end end # check for wildcard as last char if search_str.ends_with? '*' wildcard_re += ".*" end wildcard_re = "^" + wildcard_re + "$" /#{wildcard_re}/.match(value) end |
Instance Method Details
#active? ⇒ Boolean
17 18 19 |
# File 'app/controllers/applications_controller.rb', line 17 def active? @filtered end |
#apply(applications) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/applications_controller.rb', line 25 def apply(applications) @filtered = !applications.empty? @type_options = [['All','']] types = {} applications.select do |application| type = application.framework unless types.has_key? type @type_options << [application.framework_name, type] types[type] = true end ApplicationsFilter.wildcard_match?(@name, application.name) && (@type.nil? or @type.blank? or @type == type) end end |
#persisted? ⇒ Boolean
13 14 15 |
# File 'app/controllers/applications_controller.rb', line 13 def persisted? false end |
#present? ⇒ Boolean
21 22 23 |
# File 'app/controllers/applications_controller.rb', line 21 def present? !(name.nil? or name.blank?) or !(type.nil? or type.blank?) end |