Class: UnLocode::Locode
- Inherits:
-
BaseRecord
- Object
- ActiveRecord::Base
- BaseRecord
- UnLocode::Locode
- Defined in:
- lib/un_locode/locode.rb
Class Method Summary collapse
- .find_by_fuzzy_name(name, limit = 10) ⇒ Object
- .find_by_name_and_function(name, function, limit = 10) ⇒ Object
Instance Method Summary collapse
Class Method Details
.find_by_fuzzy_name(name, limit = 10) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/un_locode/locode.rb', line 14 def self.find_by_fuzzy_name name, limit = 10 where('name like ? or name_wo_diacritics like ? or alternative_name like ? or alternative_name_wo_diacritics like ?', "%#{name}%", "%#{name}%", "%#{name}%", "%#{name}%").limit(limit) end |
.find_by_name_and_function(name, function, limit = 10) ⇒ Object
22 23 24 25 |
# File 'lib/un_locode/locode.rb', line 22 def self.find_by_name_and_function name, function, limit = 10 raise "Unsupported Locode Function! Should be one of #{UnLocode::FUNCTIONS.join(' ')}." unless UnLocode::FUNCTIONS.include?(function) find_by_fuzzy_name(name).where(function => true).limit(limit) end |
Instance Method Details
#as_json(options = {}) ⇒ Object
27 28 29 |
# File 'lib/un_locode/locode.rb', line 27 def as_json = {} super(.merge!(except: [:id, :country_id])).merge('country' => country.as_json) end |