Class: TwitterCldr::Shared::PostalCodes

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/shared/postal_codes.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(territory, regexp, ast) ⇒ PostalCodes

Returns a new instance of PostalCodes.



46
47
48
49
50
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 46

def initialize(territory, regexp, ast)
  @territory = territory
  @regexp = regexp
  @ast = ast
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



44
45
46
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 44

def ast
  @ast
end

#regexpObject (readonly)

Returns the value of attribute regexp.



44
45
46
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 44

def regexp
  @regexp
end

#territoryObject (readonly)

Returns the value of attribute territory.



44
45
46
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 44

def territory
  @territory
end

Class Method Details

.for_territory(territory) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 19

def for_territory(territory)
  key = territory.to_s.downcase.to_sym
  if res = resource[key]
    territory_cache[key] ||= new(
      territory,
      res[:regex],
      TwitterCldr::Utils::RegexpAst.load(res[:ast])
    )
  else
    raise InvalidTerritoryError, "invalid territory"
  end
end

.territoriesObject



15
16
17
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 15

def territories
  resource.keys
end

Instance Method Details

#sample(sample_size = 1) ⇒ Object



56
57
58
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 56

def sample(sample_size = 1)
  generator.sample(sample_size)
end

#valid?(postal_code) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 52

def valid?(postal_code)
  !!(regexp && regexp =~ postal_code)
end