diff --git a/lib/rails_country_select.rb b/lib/rails_country_select.rb index 812bc60..48969b2 100644 --- a/lib/rails_country_select.rb +++ b/lib/rails_country_select.rb @@ -1,10 +1,11 @@ # encoding: utf-8 require "rails_country_select/version" - require File.expand_path('../country_definitions', __FILE__) + if defined?(Rails) && defined?(ActionView) module ActionView module Helpers + autoload :CountryHelper, 'rails_country_select/helpers/rails_country_select' module FormOptionsHelper def country_select(object, method, options = {}, html_options = {}) options[:keys] = :names unless options.has_key?(:keys) @@ -27,6 +28,17 @@ def country_select(method, options = {}, html_options = {}) @template.country_select(@object_name, method, options.merge({:object => @object}), html_options) end end + + # get country info given some params + def country(options = {:name => "", :num =>"", :alpha2s => "", :alpha3s => ""}) + result = [] + COUNTRY_NUMS.zip(COUNTRY_NAMES, COUNTRY_ALPHA2S, COUNTRY_ALPHA3S).each do |country| + if options[:nums].to_i.eql?(country[0]) || options[:name].eql?(country[1]) || options[:alpha2s].eql?(country[2]) || options[:alpha3s].eql?(country[3]) + result = country + end + end + result + end end end end diff --git a/lib/rails_country_select/version.rb b/lib/rails_country_select/version.rb index aaaffc7..70835ad 100644 --- a/lib/rails_country_select/version.rb +++ b/lib/rails_country_select/version.rb @@ -1,3 +1,3 @@ module RailsCountrySelect - VERSION = "0.0.1" + VERSION = "0.1.0" end