Module: SecID::Normalizable

Included in:
Base
Defined in:
lib/sec_id/concerns/normalizable.rb

Overview

Provides normalization methods for identifier types.

Including classes may override SEPARATORS (default /[\s-]/) and #normalized.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SEPARATORS =

Characters stripped during normalization (whitespace and hyphens); classes may override.

/[\s-]/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Extends the including identifier class with the concern's class methods.

Parameters:

  • base (Class)

    the identifier class including this concern



16
17
18
# File 'lib/sec_id/concerns/normalizable.rb', line 16

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#normalize!self

Normalizes this identifier in place, updating #full_id.



60
61
62
63
# File 'lib/sec_id/concerns/normalizable.rb', line 60

def normalize!
  @full_id = normalized
  self
end

#normalizedString Also known as: normalize

Returns the canonical normalized form of this identifier.



46
47
48
49
# File 'lib/sec_id/concerns/normalizable.rb', line 46

def normalized
  validate!
  to_s
end

#to_pretty_sString?

Returns a human-readable formatted string, or nil if invalid.

Returns:

  • (String, nil)


68
69
70
71
72
# File 'lib/sec_id/concerns/normalizable.rb', line 68

def to_pretty_s
  return nil unless valid?

  to_s
end

#to_sString

Returns:

  • (String)


75
76
77
# File 'lib/sec_id/concerns/normalizable.rb', line 75

def to_s
  identifier.to_s
end

#to_strString

Returns:

  • (String)


80
81
82
# File 'lib/sec_id/concerns/normalizable.rb', line 80

def to_str
  to_s
end