Class: Saphyr::Fields::IsoCountryField

Inherits:
FieldBase
  • Object
show all
Defined in:
lib/saphyr/fields/iso_country_field.rb

Overview

The IsoCountry field type (ISO-3166-1 alpha 2/3).

Allowed options is: :alpha with possible values: 2 or 3

  • 2 : Mean ISO-3166-1 alpha-2 (defulat)

  • 3 : Mean ISO-3166-1 alpha-3

Constant Summary collapse

PREFIX =
'iso-country'
EXPECTED_TYPES =
String
AUTHORIZED_OPTIONS =
[:alpha]
ALPHA_2 =
[
  'AF', 'AX', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AI', 'AQ', 'AG',
  'AR', 'AM', 'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB',
  'BY', 'BE', 'BZ', 'BJ', 'BM', 'BT', 'BO', 'BQ', 'BA', 'BW',
  'BV', 'BR', 'IO', 'BN', 'BG', 'BF', 'BI', 'CV', 'KH', 'CM',
  'CA', 'KY', 'CF', 'TD', 'CL', 'CN', 'CX', 'CC', 'CO', 'KM',
  'CG', 'CD', 'CK', 'CR', 'CI', 'HR', 'CU', 'CW', 'CY', 'CZ',
  'DK', 'DJ', 'DM', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE',
  'SZ', 'ET', 'FK', 'FO', 'FJ', 'FI', 'FR', 'GF', 'PF', 'TF',
  'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GD', 'GP',
  'GU', 'GT', 'GG', 'GN', 'GW', 'GY', 'HT', 'HM', 'VA', 'HN',
  'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IM', 'IL',
  'IT', 'JM', 'JP', 'JE', 'JO', 'KZ', 'KE', 'KI', 'KP', 'KR',
  'KW', 'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT',
  'LU', 'MO', 'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MH', 'MQ',
  'MR', 'MU', 'YT', 'MX', 'FM', 'MD', 'MC', 'MN', 'ME', 'MS',
  'MA', 'MZ', 'MM', 'NA', 'NR', 'NP', 'NL', 'NC', 'NZ', 'NI',
  'NE', 'NG', 'NU', 'NF', 'MK', 'MP', 'NO', 'OM', 'PK', 'PW',
  'PS', 'PA', 'PG', 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR',
  'QA', 'RE', 'RO', 'RU', 'RW', 'BL', 'SH', 'KN', 'LC', 'MF',
  'PM', 'VC', 'WS', 'SM', 'ST', 'SA', 'SN', 'RS', 'SC', 'SL',
  'SG', 'SX', 'SK', 'SI', 'SB', 'SO', 'ZA', 'GS', 'SS', 'ES',
  'LK', 'SD', 'SR', 'SJ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'TZ',
  'TH', 'TL', 'TG', 'TK', 'TO', 'TT', 'TN', 'TR', 'TM', 'TC',
  'TV', 'UG', 'UA', 'AE', 'GB', 'US', 'UM', 'UY', 'UZ', 'VU',
  'VE', 'VN', 'VG', 'VI', 'WF', 'EH', 'YE', 'ZM', 'ZW'
]
ALPHA_3 =
[
  'AFG', 'ALA', 'ALB', 'DZA', 'ASM', 'AND', 'AGO', 'AIA', 'ATA', 'ATG',
  'ARG', 'ARM', 'ABW', 'AUS', 'AUT', 'AZE', 'BHS', 'BHR', 'BGD', 'BRB',
  'BLR', 'BEL', 'BLZ', 'BEN', 'BMU', 'BTN', 'BOL', 'BES', 'BIH', 'BWA',
  'BVT', 'BRA', 'IOT', 'BRN', 'BGR', 'BFA', 'BDI', 'CPV', 'KHM', 'CMR',
  'CAN', 'CYM', 'CAF', 'TCD', 'CHL', 'CHN', 'CXR', 'CCK', 'COL', 'COM',
  'COG', 'COD', 'COK', 'CRI', 'CIV', 'HRV', 'CUB', 'CUW', 'CYP', 'CZE',
  'DNK', 'DJI', 'DMA', 'DOM', 'ECU', 'EGY', 'SLV', 'GNQ', 'ERI', 'EST',
  'SWZ', 'ETH', 'FLK', 'FRO', 'FJI', 'FIN', 'FRA', 'GUF', 'PYF', 'ATF',
  'GAB', 'GMB', 'GEO', 'DEU', 'GHA', 'GIB', 'GRC', 'GRL', 'GRD', 'GLP',
  'GUM', 'GTM', 'GGY', 'GIN', 'GNB', 'GUY', 'HTI', 'HMD', 'VAT', 'HND',
  'HKG', 'HUN', 'ISL', 'IND', 'IDN', 'IRN', 'IRQ', 'IRL', 'IMN', 'ISR',
  'ITA', 'JAM', 'JPN', 'JEY', 'JOR', 'KAZ', 'KEN', 'KIR', 'PRK', 'KOR',
  'KWT', 'KGZ', 'LAO', 'LVA', 'LBN', 'LSO', 'LBR', 'LBY', 'LIE', 'LTU',
  'LUX', 'MAC', 'MDG', 'MWI', 'MYS', 'MDV', 'MLI', 'MLT', 'MHL', 'MTQ',
  'MRT', 'MUS', 'MYT', 'MEX', 'FSM', 'MDA', 'MCO', 'MNG', 'MNE', 'MSR',
  'MAR', 'MOZ', 'MMR', 'NAM', 'NRU', 'NPL', 'NLD', 'NCL', 'NZL', 'NIC',
  'NER', 'NGA', 'NIU', 'NFK', 'MKD', 'MNP', 'NOR', 'OMN', 'PAK', 'PLW',
  'PSE', 'PAN', 'PNG', 'PRY', 'PER', 'PHL', 'PCN', 'POL', 'PRT', 'PRI',
  'QAT', 'REU', 'ROU', 'RUS', 'RWA', 'BLM', 'SHN', 'KNA', 'LCA', 'MAF',
  'SPM', 'VCT', 'WSM', 'SMR', 'STP', 'SAU', 'SEN', 'SRB', 'SYC', 'SLE',
  'SGP', 'SXM', 'SVK', 'SVN', 'SLB', 'SOM', 'ZAF', 'SGS', 'SSD', 'ESP',
  'LKA', 'SDN', 'SUR', 'SJM', 'SWE', 'CHE', 'SYR', 'TWN', 'TJK', 'TZA',
  'THA', 'TLS', 'TGO', 'TKL', 'TON', 'TTO', 'TUN', 'TUR', 'TKM', 'TCA',
  'TUV', 'UGA', 'UKR', 'ARE', 'GBR', 'USA', 'UMI', 'URY', 'UZB', 'VUT',
  'VEN', 'VNM', 'VGB', 'VIR', 'WLF', 'ESH', 'YEM', 'ZMB', 'ZWE'
]

Constants inherited from FieldBase

FieldBase::DEFAULT_OPTS, FieldBase::DEFAULT_OPT_VALUES, FieldBase::EXCLUSIVE_OPTIONS, FieldBase::NOT_EQUALS_OPTIONS, FieldBase::NOT_SUP_OPTIONS, FieldBase::NOT_SUP_OR_EQUALS_OPTIONS, FieldBase::REQUIRED_ONE_OF_OPTIONS, FieldBase::REQUIRED_OPTIONS

Constants included from Asserts::ErrorConstants

Asserts::ErrorConstants::ERR_BAD_FORMAT, Asserts::ErrorConstants::ERR_EQ, Asserts::ErrorConstants::ERR_GT, Asserts::ErrorConstants::ERR_GTE, Asserts::ErrorConstants::ERR_IN, Asserts::ErrorConstants::ERR_LEN, Asserts::ErrorConstants::ERR_LT, Asserts::ErrorConstants::ERR_LTE, Asserts::ErrorConstants::ERR_MAX, Asserts::ErrorConstants::ERR_MIN, Asserts::ErrorConstants::ERR_NOT_EMPTY, Asserts::ErrorConstants::ERR_NOT_NULLABLE, Asserts::ErrorConstants::ERR_REGEXP, Asserts::ErrorConstants::ERR_SIZE_EQ, Asserts::ErrorConstants::ERR_SIZE_LEN, Asserts::ErrorConstants::ERR_SIZE_MAX, Asserts::ErrorConstants::ERR_SIZE_MIN, Asserts::ErrorConstants::ERR_TYPE

Instance Attribute Summary

Attributes inherited from FieldBase

#opts

Instance Method Summary collapse

Methods inherited from FieldBase

#authorized_options, #default?, #err, #exclusive_options, #expected_types, #not_equals_options, #not_sup_options, #not_sup_or_equals_options, #nullable?, #prefix, #required?, #required_one_of_options, #required_options, #validate

Methods included from Asserts::StringAssert

#assert_string_regexp

Methods included from Asserts::NumericAssert

#assert_numeric_gt, #assert_numeric_gte, #assert_numeric_lt, #assert_numeric_lte

Methods included from Asserts::SizeAssert

#assert_size_len, #assert_size_max, #assert_size_min

Methods included from Asserts::BaseAssert

#assert_boolean, #assert_class, #assert_eq, #assert_in, #assert_not_empty

Constructor Details

#initialize(opts = {}) ⇒ IsoCountryField

Returns a new instance of IsoCountryField.



71
72
73
74
75
76
77
78
79
80
# File 'lib/saphyr/fields/iso_country_field.rb', line 71

def initialize(opts={})
  if opts[:alpha].nil?
    opts[:alpha] = 2
  else
    if opts[:alpha] != 2 and opts[:alpha] != 3
      raise Saphyr::Error.new 'Bad county alpha option must be : 2 or 3'
    end
  end
  super opts
end