Module: Sinatra::Helpers::Country
- Defined in:
- lib/sinatra/helpers/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.
283 284 285 |
# File 'lib/sinatra/helpers/country.rb', line 283 def [](code) all[code.to_sym] if not code.to_s.empty? end |
.all ⇒ Hash
Gives all countries in a Hash.
296 297 298 |
# File 'lib/sinatra/helpers/country.rb', line 296 def all @all end |
.random ⇒ Symbol
For use with seeding dummy data.
289 290 291 |
# File 'lib/sinatra/helpers/country.rb', line 289 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.
267 268 269 |
# File 'lib/sinatra/helpers/country.rb', line 267 def to_select all.map { |code, name| [name, code.to_s] } end |