Sha256: 1822d4ac69c817e9e5737b57abc04effb36b4abf7670e0cee8b4f6bc84c5e342

Contents?: true

Size: 336 Bytes

Versions: 15

Compression:

Stored size: 336 Bytes

Contents

class Subregion < ActiveRecord::Base
  belongs_to :region

  def self.find_by_postcode(postcode)
    if postcode.strip.upcase =~ /^([A-Z][A-Z]?)/

      prefix = '|' + $1 + '|'
      subregions = Subregion.arel_table
      Subregion.where(subregions[:postcode_prefix].matches("%#{prefix}%")).first
    else
      nil
    end
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
kit_cms-2.3.22 app/models/subregion.rb
kit_cms-2.3.20 app/models/subregion.rb
kit_cms-2.3.19 app/models/subregion.rb
kit_cms-2.3.18 app/models/subregion.rb
kit_cms-2.3.17 app/models/subregion.rb
kit_cms-2.3.16 app/models/subregion.rb
kit_cms-2.3.15 app/models/subregion.rb
kit_cms-2.3.14 app/models/subregion.rb
kit_cms-2.3.13 app/models/subregion.rb
kit_cms-2.3.11 app/models/subregion.rb
kit_cms-2.3.10 app/models/subregion.rb
kit_cms-2.3.9 app/models/subregion.rb
kit_cms-2.3.8 app/models/subregion.rb
kit_cms-2.3.7 app/models/subregion.rb
kit_cms-2.3.6 app/models/subregion.rb