Module: Unicode::Data

Defined in:
lib/unicode/data.rb,
lib/unicode/data/version.rb,
lib/unicode/data/generate.rb,
lib/unicode/data/validate.rb

Defined Under Namespace

Classes: Generate, Validate

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.generateObject



7
8
9
10
# File 'lib/unicode/data.rb', line 7

def self.generate
  require "unicode/data/generate"
  Generate.call
end

.propertiesObject



17
18
19
20
21
22
# File 'lib/unicode/data.rb', line 17

def self.properties
  @properties ||=
    File.readlines(File.expand_path("data/derived.txt", __dir__), chomp: true).to_h do |line|
      line.split(/\s+/, 2)
    end
end

.property?(query, value) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
# File 'lib/unicode/data.rb', line 24

def self.property?(query, value)
  properties[query].split(",").any? do |segment|
    case segment
    when /^(\d+)$/
      $1.to_i == value.ord
    when /^(\d+)..(\d+)$/
      ($1.to_i..$2.to_i).cover?(value.ord)
    end
  end
end

.validateObject



12
13
14
15
# File 'lib/unicode/data.rb', line 12

def self.validate
  require "unicode/data/validate"
  Validate.call
end