Module: MirUtility

Included in:
ActionController::Base, ActiveRecord::Base, Fixnum, Float
Defined in:
lib/mir_utility.rb

Defined Under Namespace

Modules: CoreExtensions

Constant Summary collapse

MONTHS =
{
  0 => "JAN",
  1 => "FEB",
  2 => "MAR",
  3 => "APR",
  4 => "MAY",
  5 => "JUN",
  6 => "JUL",
  7 => "AUG",
  8 => "SEP",
  9 => "OCT",
  10 => "NOV",
  11 => "DEC"
}
STATE_CODES =
{ 'Alabama' => 'AL', 'Alaska' => 'AK', 'Arizona' => 'AZ', 'Arkansas' => 'AR', 'California' => 'CA', 'Colorado' => 'CO', 'Connecticut' => 'CT', 'Delaware' => 'DE', 'Florida' => 'FL', 'Georgia' => 'GA', 'Hawaii' => 'HI', 'Idaho' => 'ID', 'Illinois' => 'IL', 'Indiana' => 'IN', 'Iowa' => 'IA', 'Kansas' => 'KS', 'Kentucky' => 'KY', 'Louisiana' => 'LA', 'Maine' => 'ME', 'Maryland' => 'MD', 'Massachusetts' => 'MA', 'Michigan' => 'MI', 'Minnesota' => 'MN', 'Mississippi' => 'MS', 'Missouri' => 'MO', 'Montana' => 'MT', 'Nebraska' => 'NE', 'Nevada' => 'NV', 'New Hampshire' => 'NH', 'New Jersey' => 'NJ', 'New Mexico' => 'NM', 'New York' => 'NY', 'North Carolina' => 'NC', 'North Dakota' => 'ND', 'Ohio' => 'OH', 'Oklahoma' => 'OK', 'Oregon' => 'OR', 'Pennsylvania' => 'PA', 'Puerto Rico' => 'PR', 'Rhode Island' => 'RI', 'South Carolina' => 'SC', 'South Dakota' => 'SD', 'Tennessee' => 'TN', 'Texas' => 'TX', 'Utah' => 'UT', 'Vermont' => 'VT', 'Virginia' => 'VA', 'Washington' => 'WA', 'Washington DC' => 'DC', 'West Virginia' => 'WV', 'Wisconsin' => 'WI', 'Wyoming' => 'WY', 'Alberta' => 'AB', 'British Columbia' => 'BC', 'Manitoba' => 'MB', 'New Brunswick' => 'NB', 'Newfoundland and Labrador' => 'NL', 'Northwest Territories' => 'NT', 'Nova Scotia' => 'NS', 'Nunavut' => 'NU', 'Ontario' => 'ON', 'Prince Edward Island' => 'PE', 'Quebec' => 'QC', 'Saskatchewan' => 'SK', 'Yukon' => 'YT' }

Class Method Summary collapse

Class Method Details

.canonical_url(url) ⇒ Object



22
23
24
# File 'lib/mir_utility.rb', line 22

def self.canonical_url(url)
  (url + '/').gsub(/\/\/$/,'/')
end

.destroy_old_sessions(timestamp) ⇒ Object



26
27
28
29
30
# File 'lib/mir_utility.rb', line 26

def self.destroy_old_sessions( timestamp )
  ActiveRecord::SessionStore::Session.destroy_all(
    ['updated_at < ?', timestamp]
  )
end

.normalize(slug_text) ⇒ Object

Copied from FriendlyId 2.2.7 for backward compatibility. Use gem’s default behavior instead: github.com/norman/friendly_id.



33
34
35
36
37
38
39
40
41
42
# File 'lib/mir_utility.rb', line 33

def self.normalize(slug_text)
  return "" if slug_text.nil? || slug_text == ""
  ActiveSupport::Multibyte.proxy_class.new(slug_text.to_s).normalize(:kc).
    gsub(/[\W]/u, ' ').
    strip.
    gsub(/\s+/u, '-').
    gsub(/-\z/u, '').
    downcase.
    to_s
end

.normalize_slug(text) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/mir_utility.rb', line 44

def self.normalize_slug(text)
  warn "[DEPRECATION] `MirUtility.normalize_slug` is deprecated. Use FriendlyId's default behavior instead: http://github.com/norman/friendly_id."
  _normalized = MirUtility.normalize(text)
  _normalized.gsub!('-', '_')    # change - to _
  _normalized.gsub!(/[_]+/, '_') # truncate multiple _
  _normalized
end

.state_name_for(abbreviation) ⇒ Object



52
53
54
# File 'lib/mir_utility.rb', line 52

def self.state_name_for(abbreviation)
  STATE_CODES.value?(abbreviation.to_s.upcase) && STATE_CODES.find{|k,v| v == abbreviation.to_s.upcase}[0]
end