Class: ModelAuditor::Normalizers::String

Inherits:
Object
  • Object
show all
Defined in:
lib/model_auditor/normalizers/string.rb

Constant Summary collapse

DEFAULTS =
{
  limit: 97
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, options = {}) ⇒ String

Returns a new instance of String.



12
13
14
15
# File 'lib/model_auditor/normalizers/string.rb', line 12

def initialize(value, options = {})
  @value = value
  @options = DEFAULTS.merge options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/model_auditor/normalizers/string.rb', line 6

def options
  @options
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/model_auditor/normalizers/string.rb', line 6

def value
  @value
end

Instance Method Details

#normalizeObject



17
18
19
20
21
# File 'lib/model_auditor/normalizers/string.rb', line 17

def normalize
  return value unless valid?

  value.truncate(limit)
end

#valid?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/model_auditor/normalizers/string.rb', line 23

def valid?
  value.present? && value.respond_to?(:truncate)
end