Module: Sinatra::Country
- Defined in:
- lib/sinatra/support/country.rb
Overview
A simple module containing all countries as of 2010.
Class Method Summary (collapse)
-
+ (String?) [](code)
Retrieves the country name given a country code.
-
+ (Hash) all
Gives all countries in a Hash.
-
+ (Symbol) random
For use with seeding dummy data.
-
+ (Array) to_select
A collection of pairs with the first element being country name and the last element being the code.
Class Method Details
+ (String?) [](code)
Retrieves the country name given a country code.
282 283 284 |
# File 'lib/sinatra/support/country.rb', line 282 def [](code) all[code.to_sym] if not code.to_s.empty? end |
+ (Hash) all
Gives all countries in a Hash.
295 296 297 |
# File 'lib/sinatra/support/country.rb', line 295 def all @all end |
+ (Symbol) random
For use with seeding dummy data.
288 289 290 |
# File 'lib/sinatra/support/country.rb', line 288 def random all.keys.shuffle.first end |
+ (Array) to_select
A collection of pairs with the first element being country name and the last element being the code.
266 267 268 |
# File 'lib/sinatra/support/country.rb', line 266 def to_select all.map { |code, name| [name, code.to_s] } end |