class ActiveAdmin::Filters::Humanized
Public Class Methods
new(param)
click to toggle source
# File lib/active_admin/filters/humanized.rb, line 7 def initialize(param) @body = param[0] @value = param[1] end
Public Instance Methods
body()
click to toggle source
# File lib/active_admin/filters/humanized.rb, line 16 def body predicate = ransack_predicate_translation if current_predicate.nil? predicate = @body.titleize elsif translation_missing?(predicate) predicate = active_admin_predicate_translation end "#{parse_parameter_body} #{predicate}".strip end
value()
click to toggle source
# File lib/active_admin/filters/humanized.rb, line 12 def value @value.is_a?(::Array) ? @value.compact.join(', ') : @value end
Private Instance Methods
active_admin_predicate_translation()
click to toggle source
# File lib/active_admin/filters/humanized.rb, line 57 def active_admin_predicate_translation translation = I18n.t("active_admin.filters.predicates.#{current_predicate}").downcase end
current_predicate()
click to toggle source
# File lib/active_admin/filters/humanized.rb, line 45 def current_predicate @current_predicate ||= predicates.detect { |p| @body.end_with?("_#{p}") } end
parse_parameter_body()
click to toggle source
# File lib/active_admin/filters/humanized.rb, line 30 def parse_parameter_body return if current_predicate.nil? # Accounting for strings that might contain other predicates. Example: # 'requires_approval' contains the substring 'eq' split_string = "_#{current_predicate}" @body.split(split_string) .first .gsub('_', ' ') .strip .titleize .gsub('Id', 'ID') end
predicates()
click to toggle source
# File lib/active_admin/filters/humanized.rb, line 49 def predicates Ransack::Predicate.names_by_decreasing_length end
ransack_predicate_translation()
click to toggle source
# File lib/active_admin/filters/humanized.rb, line 53 def ransack_predicate_translation I18n.t("ransack.predicates.#{current_predicate}") end
translation_missing?(predicate)
click to toggle source
# File lib/active_admin/filters/humanized.rb, line 61 def translation_missing?(predicate) predicate.downcase.include?('translation missing') end