Class: Kiba::Extend::Transforms::Helpers::DelimOnlyChecker
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Helpers::DelimOnlyChecker
- Defined in:
- lib/kiba/extend/transforms/helpers/delim_only_checker.rb
Overview
Service object to return whether given values are “delimiter only”.
NOTE: By default, “delimiter only” is true
if a value is nil
or empty?
. It is also true
if the value consists of only the given delim
and, optionally, any spaces. If given one or more
treat_as_null
values, it is true if the value consists of those “null” strings, the given
delimiter, and spaces only. If you specify blank_result: false
, then values that are nil
or
empty?
will not count as “delimiter only”
Class Method Summary collapse
Instance Method Summary collapse
-
#call(value) ⇒ true, false
-
#initialize(delim: Kiba::Extend.delim, treat_as_null: nil, blank_result: true) ⇒ DelimOnlyChecker
constructor
A new instance of DelimOnlyChecker.
Constructor Details
#initialize(delim: Kiba::Extend.delim, treat_as_null: nil, blank_result: true) ⇒ DelimOnlyChecker
Returns a new instance of DelimOnlyChecker.
29 30 31 32 33 34 35 36 |
# File 'lib/kiba/extend/transforms/helpers/delim_only_checker.rb', line 29 def initialize(delim: Kiba::Extend.delim, treat_as_null: nil, blank_result: true) @delim = delim @nullvals = treat_as_null.nil? ? nil : [treat_as_null].flatten.sort_by do |val| val.length end.reverse @blank_result = blank_result end |
Class Method Details
.call(delim:, value:, treat_as_null:, blank_result:) ⇒ Object
20 21 22 23 |
# File 'lib/kiba/extend/transforms/helpers/delim_only_checker.rb', line 20 def call(delim:, value:, treat_as_null:, blank_result:) new(delim: delim, treat_as_null: treat_as_null, blank_result: blank_result).call(value) end |
Instance Method Details
#call(value) ⇒ true, false
41 42 43 44 45 46 47 48 49 |
# File 'lib/kiba/extend/transforms/helpers/delim_only_checker.rb', line 41 def call(value) return blank_result if value.nil? no_nulls = nullvals ? remove_nulls(value) : value.strip return blank_result if no_nulls.empty? no_delims = no_nulls.gsub(delim, "").strip no_delims.empty? end |