Module: Sinatra::Country
- Defined in:
- lib/sinatra/support/country.rb
Overview
A simple module containing all countries as of 2010.
Class Method Summary collapse
-
.[](code) ⇒ String?
Retrieves the country name given a country code.
-
.all ⇒ Hash
Gives all countries in a Hash.
-
.random ⇒ Symbol
For use with seeding dummy data.
-
.to_select ⇒ Array
A collection of pairs with the first element being country name and the last element being the code.
Class Method Details
.[](code) ⇒ String?
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 |
.all ⇒ Hash
Gives all countries in a Hash.
295 296 297 |
# File 'lib/sinatra/support/country.rb', line 295 def all @all end |
.random ⇒ Symbol
For use with seeding dummy data.
288 289 290 |
# File 'lib/sinatra/support/country.rb', line 288 def random all.keys.shuffle.first end |
.to_select ⇒ Array
Returns 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 |