Module: Forkforge::Category
- Defined in:
- lib/forkforge/category.rb
Class Method Summary collapse
-
.included(base) ⇒ Object
Letter::all_raw | Letter::uppercase_raw | Letter::uppercase 'Alexei' # ⇒ 'A' Letter::uppercase_code_point | Mark::non_spacing_bidirectional_category.
Class Method Details
.included(base) ⇒ Object
Letter::all_raw | Letter::uppercase_raw | Letter::uppercase 'Alexei' # ⇒ 'A' Letter::uppercase_code_point | Mark::non_spacing_bidirectional_category
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/forkforge/category.rb', line 10 def self.included base base.const_get(:TYPES).each { |type| base.class_eval %Q{ def #{type.last}_raw @@#{type.last} ||= Forkforge::UnicodeData::all_general_category /#{type.first}/ end def is_#{type.last} s UnicodeData::infos(s).inject(true) { |memo, kv| memo &&= kv[:general_category] == "#{type.first}" } end def #{type.last} s = nil @@#{type.last}_array ||= #{type.last}_raw.map { |k, v| Forkforge::UnicodeData::to_char k } s.respond_to?(:scan) ? s.scan(Regexp.new(@@#{type.last}_array.join '|')) : @@#{type.last}_array end } CodePoint::UNICODE_FIELDS.each { |method| base.class_eval %Q{ def #{type.last}_#{method} @@#{type.last}_#{method} ||= #{type.last}_raw.map { |k, v| [ Forkforge::UnicodeData::to_char(k), Forkforge::UnicodeData::get_#{method}(k) ] }.to_h end } } } base.extend base end |