Class: UnitedStates::State::PostalCode

Inherits:
Object
  • Object
show all
Defined in:
lib/united_states/state/postal_code.rb

Overview

A U.S. State postal code.

Defined Under Namespace

Classes: StringTooLongError, StringTooShortError

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ UnitedStates::State::PostalCode

Parameters:

  • string (String)

    the postal code of the State

Raises:



36
37
38
39
40
41
# 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

Instance Method Details

#==(other) ⇒ Boolean

Returns whether or not other.to_s matches self.to_s.

Parameters:

Returns:

  • (Boolean)

    whether or not other.to_s matches self.to_s



46
47
48
# File 'lib/united_states/state/postal_code.rb', line 46

def ==(other)
  other.to_s == to_s
end

#lowercaseString

Returns an all lowercase version of this PostalCode.

Returns:

  • (String)

    an all lowercase version of this PostalCode



52
53
54
# File 'lib/united_states/state/postal_code.rb', line 52

def lowercase
  @string.downcase
end

#to_sString

Returns an all uppercase version of this PostalCode.

Returns:

  • (String)

    an all uppercase version of this PostalCode



64
65
66
# File 'lib/united_states/state/postal_code.rb', line 64

def to_s
  uppercase
end

#uppercaseString

Returns an all uppercase version of this PostalCode.

Returns:

  • (String)

    an all uppercase version of this PostalCode



58
59
60
# File 'lib/united_states/state/postal_code.rb', line 58

def uppercase
  @string.upcase
end