Class: Objective::Filters::StringFilter
Instance Attribute Summary
#key, #sub_filters
Instance Method Summary
collapse
#default, #default?, #dup, #feed, #feed_empty, #feed_invalid, #feed_nil, #feed_none, #feed_result, filter_name, #handle_errors, inherited, #initialize, #options, #sub_filters_hash, #type_specific_options_hash
Instance Method Details
#coercable?(raw) ⇒ Boolean
13
14
15
|
# File 'lib/objective/filters/string_filter.rb', line 13
def coercable?(raw)
options.coercable_classes.map { |klass| raw.is_a?(klass) }.any?
end
|
#coerce(raw) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/objective/filters/string_filter.rb', line 5
def coerce(raw)
return raw unless raw.is_a?(String) || coercable?(raw)
tmp = raw.is_a?(BigDecimal) ? raw.to_s(options.decimal_format) : raw.to_s
tmp = tmp.gsub(/[^[:print:]\t\r\n]+/, ' ') unless options.allow_control_characters
tmp = tmp.strip if options.strip
tmp
end
|
#coerce_error(coerced) ⇒ Object
17
18
19
|
# File 'lib/objective/filters/string_filter.rb', line 17
def coerce_error(coerced)
return :string unless coerced.is_a?(String)
end
|
#validate(coerced) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/objective/filters/string_filter.rb', line 21
def validate(coerced)
return :empty if coerced.empty?
return :min if options.min && coerced.length < options.min
return :max if options.max && coerced.length > options.max
return :in if options.in && !options.in.include?(coerced)
return :matches if options.matches && (options.matches !~ coerced)
end
|