Module: Babosa::Characters

Extended by:
Characters
Included in:
Characters
Defined in:
lib/babosa/characters.rb

Overview

This module provides sets of characters needed for various UTF-8 aware string operations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#approximationsObject (readonly)

Hash of UTF-8 - ASCII approximations.



10
11
12
# File 'lib/babosa/characters.rb', line 10

def approximations
  @approximations
end

#strippableObject (readonly)

Punctuation and control characters to remove from slug strings.



12
13
14
# File 'lib/babosa/characters.rb', line 12

def strippable
  @strippable
end

Instance Method Details

#add_approximations(name, hash) ⇒ Object

Adds a hash of approximations.

Examples:

add_approximations :spanish, "ñ" => "ni"

Parameters:

  • name (#to_sym)

    The name of the approximations to add.

  • Hash

    hash The approximations to add.



28
29
30
31
32
33
34
35
36
37
# File 'lib/babosa/characters.rb', line 28

def add_approximations(name, hash)
  approximations = @approximations ? @approximations.dup : {}
  approximations[name.to_sym] = hash.inject({}) do |memo, object|
    key = object[0].unpack("U").shift
    value = object[1].unpack("C*")
    memo[key] = value.length == 1 ? value[0] : value
    memo
  end.freeze
  @approximations = approximations.freeze
end