Class: TwitterCldr::Shared::PostalCodes
- Inherits:
-
Object
- Object
- TwitterCldr::Shared::PostalCodes
- Defined in:
- lib/twitter_cldr/shared/postal_codes.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#territory ⇒ Object
readonly
Returns the value of attribute territory.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(territory, regexp, ast) ⇒ PostalCodes
constructor
A new instance of PostalCodes.
- #sample(sample_size = 1) ⇒ Object
- #valid?(postal_code) ⇒ Boolean
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
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
44 45 46 |
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 44 def ast @ast end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
44 45 46 |
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 44 def regexp @regexp end |
#territory ⇒ Object (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 |
.territories ⇒ Object
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
52 53 54 |
# File 'lib/twitter_cldr/shared/postal_codes.rb', line 52 def valid?(postal_code) !!(regexp && regexp =~ postal_code) end |