Class: PostalCoder::Formats::AbstractFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/postalcoder/formats.rb

Direct Known Subclasses

CAPostalCode, USZipCode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_value) ⇒ AbstractFormat

Returns a new instance of AbstractFormat.



60
61
62
63
64
65
66
# File 'lib/postalcoder/formats.rb', line 60

def initialize(raw_value)
  unless raw_value.is_a?(String)
    raise ArgumentError, "value must be String, not: #{raw_value.class}"
  end
  @value = cleanup(raw_value)
  validate_form!
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



58
59
60
# File 'lib/postalcoder/formats.rb', line 58

def value
  @value
end

Instance Method Details

#cleanup(raw_value) ⇒ Object



72
73
74
# File 'lib/postalcoder/formats.rb', line 72

def cleanup(raw_value)
  raw_value.upcase.gsub(/\s|\-/, '')
end

#has_valid_form?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


76
77
78
79
# File 'lib/postalcoder/formats.rb', line 76

def has_valid_form?
  raise NotImplementedError, "#{self.class}#has_valid_form? must be " \
  'implemented.'
end

#to_sObject



68
69
70
# File 'lib/postalcoder/formats.rb', line 68

def to_s
  value
end