Sha256: 36fb0f5ef74ed16724c2f6dd332117edc5b5fa6af9feefa90d4b46dc44d4d02b

Contents?: true

Size: 940 Bytes

Versions: 8

Compression:

Stored size: 940 Bytes

Contents

class CharacterSet
  module PredefinedSets
    Dir[File.join(__dir__, 'predefined_sets', '*.cps')].each do |path|
      set_name = File.basename(path, '.cps')

      class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{set_name}
          @#{set_name} ||= build_from_cps_file('#{path}').freeze
        end

        def non_#{set_name}
          @non_#{set_name} ||= build_from_cps_file('#{path}').inversion.freeze
        end
      RUBY
    end

    alias all                      any
    alias ascii_letters            ascii_letter
    alias basic_multilingual_plane bmp
    alias blank                    whitespace
    alias invalid                  surrogate
    alias valid                    unicode

    def build_from_cps_file(path)
      File.readlines(path).inject(new) do |set, line|
        range_start, range_end = line.split(',')
        set.merge((range_start.to_i(16))..(range_end.to_i(16)))
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
character_set-1.5.0-java lib/character_set/predefined_sets.rb
character_set-1.5.0 lib/character_set/predefined_sets.rb
character_set-1.4.1-java lib/character_set/predefined_sets.rb
character_set-1.4.1 lib/character_set/predefined_sets.rb
character_set-1.4.0-java lib/character_set/predefined_sets.rb
character_set-1.4.0 lib/character_set/predefined_sets.rb
character_set-1.3.0-java lib/character_set/predefined_sets.rb
character_set-1.3.0 lib/character_set/predefined_sets.rb