Class: PostalCoder::Formats::AbstractFormat
- Inherits:
-
Object
- Object
- PostalCoder::Formats::AbstractFormat
- Defined in:
- lib/postalcoder/formats.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #cleanup(raw_value) ⇒ Object
- #has_valid_form? ⇒ Boolean
-
#initialize(raw_value) ⇒ AbstractFormat
constructor
A new instance of AbstractFormat.
- #to_s ⇒ Object
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
#value ⇒ Object (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
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_s ⇒ Object
68 69 70 |
# File 'lib/postalcoder/formats.rb', line 68 def to_s value end |