Module: Slugity::Matchers

Defined in:
lib/slugity/matchers.rb,
lib/slugity/matchers/default.rb

Constant Summary collapse

@@matchers =
{
  # define the default matchers
  default: {
     # symbols
    /\s|\// => '-',
    /\~|~/ => '-',
    /_/ => '_',
    /\&/ => 'and',
    /\+/ => 'plus',
    /\=/ => 'equals',
    // => 'tel',
    // => 'tm',
    // => 'sm',
    /²/ => '2',
    /³/ => '3',
     # a
    /[ÀÁÂÃÄÅàáâãäåĀāĂ㥹ᴀ⒜ⒶaǍǎǞǟǠǡǺǻȃȀȁȂȦȧȺḀḁẚẠạẢảẤấẦầẨẩẪẫẬậẮắẰằẲẳẴẵẶặÅɑₐⓐA]/ => 'a',
    /[Ꜳꜳ]/ => 'aa',
    // => 'ac',
    /[ÆæǢǣǼǽᴁᴂ]/ => 'ae',
    /[ꜺꜻꜼꜽ]/ => 'af',
    /[Ꜷꜷ]/ => 'aj',
    // => 'as',
    /[Ꜵꜵ]/ => 'ao',
    /[Ꜹꜹ]/ => 'av',
     # b
    /[ƀƁƄƅɃᴃḂḃḄḅḆḇℬ⒝ⒷⓑBbẞ]/ => 'b',
     # c
    /[ÇçĆćĈĉĊċČčƇƈȻȼᴄḈḉℂ℃℄⒞ⒸⓒCc]/ => 'c',
    // => 'co',
    // => 'cu',
     # d
    /[ÐĎďĐđƉƊɗᴅᴆḊḋḌḍḎḏḐḑḒḓ⒟ⒹⓓDd]/ => 'd',
    /ȸ/ => 'db',
    /[DŽDždžDZDzdz]/ => 'dz',
     # e
    /[ÈÉÊËèéêëĒēĔĕĖėĘęĚěƐǝȄȅȆȇȨȩɆɇᴇḔḕḖḗḘḙḚḛḜḝẸẹẺẻẼẽẾếỀềỂểỄễỆệₑ℮ℯ⒠ⒺⓔEe]/ => 'e',
     # f
    /[ƑƒḞḟ℉⒡ⒻⓕꜰFf]/ => 'f',
     # g
    /[ĜĝĞğĠġĢģƓǤǥǦǧǴǵɠɡɢḠḡℊ⒢ⒼⓖGg]/ => 'g',
     # h
    /[ĤĥĦħȞȟḢḣḤḥḦḧḨḩḪḫẖℋℌℍℎℏ⒣ⒽⓗHh]/ => 'h',
     # i
    /[ÌÍÎÏìíîïĨĩĪīĬĭĮįƖƗǏǐȈȉȊȋḬḭḮḯ⒤ⒾⓘIi]/ => 'i',
    /[IJij]/ => 'ij',
     # j
    /[ĴĵǰȷɈɉᴊ⒥ⒿⓙJj]/ => 'j',
     # k
    /[ĶķĸƘƙǨǩᴋḰḱḲḳḴḵK⒦ⓀⓚKk]/ => 'k',
     # l
    /[İıĹĺĻļĽľĿŀŁłȽȾᴌḶḷḸḹḺḻḼḽ⒧ⓁⓛLl]/ => 'l',
    /[LJLjlj]/ => 'lj',
     # m
    /[ɱᴍḾḿṀṁṂṃ⒨ⓂⓜMm]/ => 'm',
     # n
    /[ÑñŃńŅņŇňʼnŊŋƝƞǸǹȠᴎṄṅṆṇṈṉṊṋℕ⒩ⓃⓝNn]/ => 'n',
    /[Ƌƌ]/ => 'nd',
    /[NJNjnj]/ => 'nj',
     # o
    /[ÒÓÔÕÖØðòóôõöøŌōŎŏŐőƟƠơǑǒǪǫǬǭǾǿȌȍȎȏȪȫȬȭȮȯȰȱɵᴏṌṍṎṏṐṑṒṓỌọỎỏỐốỒồỔổỖỗỘộỚớỜờỞởỠỡỢợₒ⒪ⓄⓞOo]/ => 'o',
    /[Œœɶ]/ => 'oe',
     # p
    /[ƤƥṔṕṖṗ℗ℙ⒫ⓅⓟPp]/ => 'p',
    // => 'px',
     # q
    /[ƼƽɊɋℚ⒬ⓆⓠQq]/ => 'q',
    /ȹ/ => 'qp',
     # r
    /[ŔŕŖŗŘřƦȐȑȒȓɌɍṘṙṚṛṜṝṞṟℛℜℝ℟⒭ⓇⓡRr]/ => 'r',
     # s
    /[ŚśŜŝŞşŠšſƧƨƩȘșȿṠṡṢṣṤṥṦṧṨṩ⒮ⓈⓢꜱSs]/ => 's',
    /[ß]/ => 'ss',
     # t
    /[ŢţŤťŦŧƪƫƬƭƮȚțṪṫṬṭṮṯṰṱẗ⒯ⓉⓣTt]/ => 't',
    /[Þþ]/ => 'th',
     # u
    /[µÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųƯưƱƲǓǔǕǖǗǘǙǚǛǜȕȖȗɄṲṳṴṵṶṷṸṹṺṻỤụỦủỨứỪừỬửỮữỰự⒰ⓊⓤUuȔ]/ => 'u',
     # v
    /[ɅṼṽṾṿ⒱ⓋⓥVv]/ => 'v',
     # w
    /[ŴŵƜɯẀẁẂẃẄẅẆẇẈẉẘ⒲ⓌⓦWw]/ => 'w',
     # x
    /[×ẊẋẌẍₓ⒳ⓍⓧXx]/ => 'x',
     # y
    /[ÝýÿŶŷŸȲȳɏẎẏẙỲỳỴỵỶỷỸỹ⒴ⓎⓨYyɎ]/ => 'y',
     # z
    /[ŹźŻżŽžƵƶƷȤȥɀẐẑẒẓẔẕℤ⒵ⓏⓩZz]/ => 'z',
     # numbers
    // => '0',
    // => '9',
    // => '10',
    // => '11',
    // => '12',
    // => '13',
    // => '14',
    // => '15',
    // => '16',
    // => '17',
    // => '18',
    // => '19',
    // => '20',
  }
}

Class Method Summary collapse

Class Method Details

.add(key, use_default = true, options = {}) ⇒ Object

add a matcher hash

Parameters:

  • key (Symbol)
  • use_default (Boolean) (defaults to: true)
  • options (Hash) (defaults to: {})


18
19
20
21
22
23
# File 'lib/slugity/matchers.rb', line 18

def self.add key, use_default=true, options={}
  if use_default
    options = @@matchers[:default].merge(options)
  end
  @@matchers[key] = options
end

.use(key) ⇒ Hash

fetch a matcher

Parameters:

  • key (Symbol)

Returns:

  • (Hash)


10
11
12
# File 'lib/slugity/matchers.rb', line 10

def self.use key
  @@matchers[key]
end