class UnitedStates::State::Designation

Represents the various way to designate a state (e.g. name, postal code).

Attributes

name[R]

@return [UnitedStates::State::Name]

the state's name
postal_code[R]

@return [UnitedStates::State::PostalCode]

the state's postal code

Public Class Methods

from_hash(**hash) click to toggle source

@example From Named Parameters

UnitedStates::State::Designation.from_hash(
  name: 'Hawaii', postal_code: 'HI')
# => #<UnitedStates::State::Designation:0x...@string="HI">>

@example From Variable

hawaii_hash = { name: 'Hawaii', postal_code: 'HI' }
UnitedStates::State::Designation.from_hash(hawaii_hash)
# => #<UnitedStates::State::Designation:0x...@string="HI">>

@param hash [Hash]

a hash of Designation attributes, see {#initialize} for parameters

@return [UnitedStates::State::Designation]

a Designation with attributes provided via hash
# File lib/united_states/state/designation.rb, line 30
def self.from_hash(**hash)
  new(name: hash[:name], postal_code: hash[:postal_code])
end
new(name:, postal_code:) click to toggle source

@example

UnitedStates::State::Designation.new(
  name: 'wyoming', postal_code: 'wy')
# => #<UnitedStates::State::Designation:0x007...@string="wy">>

@param name [String] @param postal_code [String] @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/designation.rb, line 44
def initialize(name:, postal_code:)
  @name = UnitedStates::State::Name.new(name)
  @postal_code = UnitedStates::State::PostalCode.new(postal_code)
end

Public Instance Methods

==(other) click to toggle source

@param other [UnitedStates::State::Designation] @return [Boolean]

whether or not other's name and postal code is equal
to this Designation's name and postal code
# File lib/united_states/state/designation.rb, line 53
def ==(other)
  other.name == name &&
    other.postal_code == postal_code
end