Class | String
In: | lib/efaber.rb
Parent: | Object

### Methods

prepare_for_query strip_html strip_version tildes to_ferret_search_string to_tag

### Public Instance methods

prepare_for_query()

[Source]

        # File lib/efaber.rb, line 44
    44:   def prepare_for_query
    45:     # Esta la usamos allá donde los selects vayan a ser con "like 'xxx%'",
    46:     # y por lo tanto, no queremos quitar ni los signos de puntuacion ni las
    47:     # palabras comunes
    48:     palabra = self
    49:
    50:     # Primero quitamos las tildes
    51:     search_string = palabra.tildes
    52:
    53:     # Sustituimos muchos espacios por uno solo
    54:     search_string = search_string.gsub(/[[:space:]]+/, " ")
    55:     # Quitamos los espacios al principio y el final
    56:     search_string = search_string.strip
    57:     search_string = search_string.downcase
    58:   end

strip_html()

[Source]

        # File lib/efaber.rb, line 40
    40:   def strip_html
    41:     self.gsub(/<\/?[^>]*>/,  "")
    42:   end

strip_version()

[Source]

        # File lib/efaber.rb, line 88
    88:   def strip_version
    89:     self.sub(/\?\d+$/, '')
    90:   end

tildes()

Convert non-ASCII characters to their ASCII equivalent. (from www.bigbold.com/snippets/posts/show/1818)

[Source]

        # File lib/efaber.rb, line 5
     5:   def tildes
     6:     foo = self.dup
     7:     foo.gsub!(/[ĄÀÁÂÃ]/,'A')
     8:     foo.gsub!(/[âäàãáäåāăǎǟǡǻȁȃȧẵặ]/,'a')
     9:     foo.gsub!(/[ÉĘÈ]/, 'E')
    10:     foo.gsub!(/[ëêéèẽēĕėẻȅȇẹȩęḙḛềếễểḕḗệḝ]/,'e')
    11:     foo.gsub!(/[ÌÍÎĨÏ]/, 'I')
    12:     foo.gsub!(/[iìíîĩīĭïỉǐịįȉȋḭɨḯ]/,'i')
    13:     foo.gsub!(/[ÒÓÔÕÖ]/, 'O')
    14:     foo.gsub!(/[òóôõōŏȯöỏőǒȍȏơǫọɵøồốỗổȱȫȭṍṏṑṓờớỡởợǭộǿ]/,'o')
    15:     foo.gsub!(/[ÙÚÛŨÜ]/, 'U')
    16:     foo.gsub!(/[ùúûũūŭüủůűǔȕȗưụṳųṷṵṹṻǖǜǘǖǚừứữửự]/,'u')
    17:     foo.gsub!(/[ỳýŷỹȳẏÿỷẙƴỵ]/,'y')
    18:     foo.gsub!(/[œ]/,'oe')
    19:     foo.gsub!(/[ÆǼǢæ]/,'ae')
    20:     foo.gsub!(/[ñǹńŃÑ]/,'n')
    21:     foo.gsub!(/[ÇĆ]/, 'C')
    22:     foo.gsub!(/[çć]/,'c')
    23:     foo.gsub!(/[ß]/,'ss')
    24:     foo.gsub!(/[œ]/,'oe')
    25:     foo.gsub!(/[ĳ]/,'ij')
    26:     foo.gsub!(/[Łł]/,'l')
    27:     foo.gsub!(/[śŚ]/,'s')
    28:     foo.gsub!(/ŹŻ/, 'Z')
    29:     foo.gsub!(/[źż]/,'z')
    30:     foo
    31:   end

to_ferret_search_string()

[Source]

        # File lib/efaber.rb, line 60
    60:   def to_ferret_search_string
    61:     unwanted_words_list =  %w{con del las los para por que una}
    62:
    63:     query_string = self
    64:
    65:     # cambiar muchos espacios por uno y mantener juntas las palabras entre comillas,
    66:     search_string = query_string.prepare_for_query.gsub(/("[^"]+")/) { $1.gsub(/\s+/,'@') }
    67:
    68:     # quitar palabras comunes y palabras de 1 o 2 letras salvo para las frases entre comillas
    69:     search_words = search_string.split(" ").map do |w|
    70:       w.gsub!(/[[:punct:]]/, "") unless w.match(/^["]/)
    71:       w if (w.length > 2) && !unwanted_words_list.include?(w)
    72:     end.compact
    73:
    74:     # If any of the words ends in "s", assume it is plural
    75:     # and search also the singular form
    76:     search_words.each do |w|
    77:       search_words << w[0..-2] if w.match(/s$/)
    78:     end
    79:
    80:     search_string = search_words.length > 1 ? "(" + search_words.compact.join(" OR ") + ")" : search_words.to_s
    81:
    82:     # volver a poner los espacios en los textos entre comillas.
    83:     search_string = search_string.gsub(/@/,' ')
    84:
    85:     search_string
    86:   end

to_tag()

[Source]

        # File lib/efaber.rb, line 33
    33:   def to_tag
    34:     return if self.nil?
    35:     output = self.dup
    36:     output = output.tildes.strip.downcase
    37:     output.gsub(/[^a-z0-9_]+/, '').gsub(/-+$/, '').gsub(/^-+$/, '')
    38:   end

[Validate]