Module: Forkforge::Selector

Included in:
BidirectionalCategory, TaggedCharacterName
Defined in:
lib/forkforge/selector.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/forkforge/selector.rb', line 7

def self.included base
  re, basename = nil, base.name.gsub(/.*::/, '')
  # FILTER = { 'Tagged' => /^<.*?>$/ }
  if base.const_defined?(:FILTER)
    filter = base.const_get(:FILTER).to_a.flatten
    re = filter.last
    basename = basename.gsub(/^#{filter.first}/, '')
  end
  basename = (Forkforge::Unicode::camel_to_underscore basename).to_sym

  # HASH = Forkforge::UnicodeData::all_character_name /^<.*?>$/
  base.const_set :HASH, UnicodeData::send("all_#{basename}", re)

  # ALL = Forkforge::UnicodeData::all_bidirectional_category.uniq
  base.const_set :ALL, base::HASH.map { |k, v| v[basename] }.uniq

  base.class_eval %Q{
    CHARACTERS = HASH.reduce({}) { |memo, v|
      (memo[v.last[:#{basename}]] ||= []) << v.last
      memo
    }
  }

  base.extend base
end