Module: ICU::Collation

Defined in:
lib/ffi-icu/collation.rb

Defined Under Namespace

Classes: Collator

Constant Summary collapse

ATTRIBUTES =
{
    french_collation: 0,
    alternate_handling: 1,
    case_first: 2,
    case_level: 3,
    normalization_mode: 4,
    strength: 5,
    hiragana_quaternary_mode: 6,
    numeric_collation: 7,
}.freeze
ATTRIBUTE_VALUES =
{
    nil => -1,
    primary: 0,
    secondary: 1,
    default_strength: 2,
    tertiary: 2,
    quaternary: 3,
    identical: 15,

    false => 16,
    true => 17,

    shifted: 20,
    non_ignorable: 21,

    lower_first: 24,
    upper_first: 25,
}.freeze
ATTRIBUTE_VALUES_INVERSE =
Hash[ATTRIBUTE_VALUES.map {|k,v| [v, k]}].freeze

Class Method Summary collapse

Class Method Details

.available_localesObject



55
56
57
58
59
# File 'lib/ffi-icu/collation.rb', line 55

def self.available_locales
  (0...Lib.ucol_countAvailable).map do |idx|
    Lib.ucol_getAvailable idx
  end
end

.collate(locale, arr) ⇒ Object



36
37
38
# File 'lib/ffi-icu/collation.rb', line 36

def self.collate(locale, arr)
  Collator.new(locale).collate(arr)
end

.keywordsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ffi-icu/collation.rb', line 40

def self.keywords
  enum_ptr = Lib.check_error { |error| Lib.ucol_getKeywords(error) }
  keywords = Lib.enum_ptr_to_array(enum_ptr)
  Lib.uenum_close enum_ptr

  hash = {}
  keywords.each do |keyword|
    enum_ptr = Lib.check_error { |error| Lib.ucol_getKeywordValues(keyword, error) }
    hash[keyword] = Lib.enum_ptr_to_array(enum_ptr)
    Lib.uenum_close(enum_ptr)
  end

  hash
end