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.



48
49
50
51
52
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 48

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

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



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

def ast
  @ast
end

#regexpObject (readonly)

Returns the value of attribute regexp.



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

def regexp
  @regexp
end

#territoryObject (readonly)

Returns the value of attribute territory.



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

def territory
  @territory
end

Class Method Details

.for_territory(territory) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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] ||= begin
      new(
        territory,
        res[:regex],
        TwitterCldr::Utils::RegexpAst.load(res[:ast])
      )
    end
  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



58
59
60
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 58

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

#valid?(postal_code) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 54

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