class UnitedStates::State::PostalCode
A U.S. State
postal code.
Public Class Methods
new(string)
click to toggle source
@param string [String]
the postal code of the State
@return [UnitedStates::State::PostalCode] @raise [UnitedStates::State::PostalCode::StringTooLongError]
if the string is over 2 characters in length
@raise [UnitedStates::State::PostalCode::StringTooShortError]
if the string is under 2 characters in length
# File lib/united_states/state/postal_code.rb, line 36 def initialize(string) string = string.to_s ensure_string_not_too_long(string) ensure_string_not_too_short(string) @string = string end
Public Instance Methods
==(other)
click to toggle source
@param other [UnitedStates::State::PostalCode] @return [Boolean]
whether or not other.to_s matches self.to_s
# File lib/united_states/state/postal_code.rb, line 46 def ==(other) other.to_s == to_s end
lowercase()
click to toggle source
@return [String]
an all lowercase version of this PostalCode
# File lib/united_states/state/postal_code.rb, line 52 def lowercase @string.downcase end
to_s()
click to toggle source
@return [String]
an all uppercase version of this PostalCode
# File lib/united_states/state/postal_code.rb, line 64 def to_s uppercase end
uppercase()
click to toggle source
@return [String]
an all uppercase version of this PostalCode
# File lib/united_states/state/postal_code.rb, line 58 def uppercase @string.upcase end
Private Instance Methods
ensure_string_not_too_long(string)
click to toggle source
@param string [String] @return [true]
if the string is under 2 characters in length
@raise [UnitedStates::State::PostalCode::StringTooLongError]
if the string is over 2 characters in length
# File lib/united_states/state/postal_code.rb, line 75 def ensure_string_not_too_long(string) return true if string.length <= 2 raise StringTooLongError, "#{string} too long, postal codes must be 2 characters" end
ensure_string_not_too_short(string)
click to toggle source
@param string [String] @return [true]
if the string is 2 characters or more in length
@raise [UnitedStates::State::PostalCode::StringTooShortError]
if the string is under 2 characters in length
# File lib/united_states/state/postal_code.rb, line 86 def ensure_string_not_too_short(string) return true if string.length >= 2 raise StringTooShortError, "#{string} too short, postal codes must be 2 characters" end