Class: UspsApi::IndiciaExtraServiceCodes

Inherits:
Object
  • Object
show all
Defined in:
lib/usps_api/models/indicia_extra_service_codes.rb

Overview

Extra Service Code requested for IMB letters, flats, and cards. * 910 - Certified Mail * 911 - Certified Mail Restricted Delivery * 930 - Insurance * 934 - Insurance Restricted Delivery * 940 - Registered Mail

* 941 - Registered Mail Restricted Delivery   * 955 - Return Receipt   *

957 - Return Receipt Electronic Note: * When the extra service code “930” is provided in the request, if the item value is over $500, “930” will automatically be replaced with “931” - Insurance (Greater than $500).

Constant Summary collapse

INDICIA_EXTRA_SERVICE_CODES =
[
  # TODO: Write general description for ENUM_910
  ENUM_910 = 910,

  # TODO: Write general description for ENUM_911
  ENUM_911 = 911,

  # TODO: Write general description for ENUM_930
  ENUM_930 = 930,

  # TODO: Write general description for ENUM_934
  ENUM_934 = 934,

  # TODO: Write general description for ENUM_940
  ENUM_940 = 940,

  # TODO: Write general description for ENUM_941
  ENUM_941 = 941,

  # TODO: Write general description for ENUM_955
  ENUM_955 = 955,

  # TODO: Write general description for ENUM_957
  ENUM_957 = 957
].freeze

Class Method Summary collapse

Class Method Details

.from_value(value, default_value = ENUM_910) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/usps_api/models/indicia_extra_service_codes.rb', line 47

def self.from_value(value, default_value = ENUM_910)
  return default_value if value.nil?

  str = value.to_s.strip
  if str.match?(/\A\d+\z/)
    num = str.to_i
    return num if INDICIA_EXTRA_SERVICE_CODES.include?(num)

    return default_value
  end

  case str.downcase
  when 'enum_910' then ENUM_910
  when 'enum_911' then ENUM_911
  when 'enum_930' then ENUM_930
  when 'enum_934' then ENUM_934
  when 'enum_940' then ENUM_940
  when 'enum_941' then ENUM_941
  when 'enum_955' then ENUM_955
  when 'enum_957' then ENUM_957
  else
    default_value
  end
end

.validate(value) ⇒ Object



41
42
43
44
45
# File 'lib/usps_api/models/indicia_extra_service_codes.rb', line 41

def self.validate(value)
  return false if value.nil?

  INDICIA_EXTRA_SERVICE_CODES.include?(value)
end