regexp_property_values 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1a85a18f01129183de1731317f4b613a8db5ebdc38fe28b4aa9476b4bf077189
4
+ data.tar.gz: e0097d3fc8d6ecbf986b3d8cf06b5e2914fb3af101749d3b62c803302591c68e
5
+ SHA512:
6
+ metadata.gz: 95f720c9ad41754521bf340f38101aace9aab770279912352de846a69f2bd2fe563022c92631baf2b343e67fe57f7dee2b3f0d051ddfcc83a5af45fa45351332
7
+ data.tar.gz: cded73ea2d0c33907fdd5d5761c30167f7c1853723ee55a1eaf063050548472198f81f2150481ae3ea76304f7e9826bcbf051d091b412fdba52934033a0ad97f
data/.gitignore CHANGED
@@ -17,6 +17,7 @@
17
17
  bbin/
18
18
  binstubs/*
19
19
  bundler_stubs/*/.yardoc
20
+ Gemfile.lock
20
21
  /.bundle/
21
22
  /_yardoc/
22
23
  /coverage/
data/README.md CHANGED
@@ -1,11 +1,16 @@
1
1
  # RegexpPropertyValues
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/regexp_property_values.svg)](http://badge.fury.io/rb/regexp_property_values)
4
+ [![Build Status](https://travis-ci.org/janosch-x/regexp_property_values.svg?branch=master)](https://travis-ci.org/janosch-x/regexp_property_values)
5
+
3
6
  This microlibrary lets you see which property values are supported by the regular expression engine of the Ruby version you are running.
4
7
 
5
8
  That is, it determines all supported values for `\p{value}` expressions.
6
9
 
7
10
  ## Usage
8
11
 
12
+ ##### Browse all property values (supported by any Ruby, ever)
13
+
9
14
  ```ruby
10
15
  require 'regexp_property_values'
11
16
 
@@ -14,15 +19,32 @@ PV = RegexpPropertyValues
14
19
  PV.all # => ["Alpha", "Blank", "Cntrl", ...]
15
20
  PV.all.sort # => ["AHex", "ASCII", "Adlam", "Adlm", "Age=1.1", ...]
16
21
 
17
- PV.by_category # => {"POSIX brackets" => ["Alpha", "Blank", ...], ...}
18
- PV.by_category.keys # => ["POSIX brackets", "Special", "Scripts", ...]
22
+ PV.by_category # => {"POSIX brackets" => ["Alpha", ...], "Special" => ...}
19
23
 
20
24
  PV.short_and_long_names # => [["M", "Grek", ...], ["Mark", "Greek", ...]]
25
+ ```
26
+
27
+ ##### Browse property values supported by the Ruby you are running
28
+
29
+ ```ruby
30
+ PV.all_for_current_ruby # => ["Alpha", "Blank", "Cntrl", ...]
31
+ PV.all_for_current_ruby.include?('Newline') # => false
32
+
33
+ PV.by_category.map { |k, v| [k, v.select(&:supported_by_current_ruby?] }
34
+
35
+ PV.short_and_long_names.map { |a| a.select(&:supported_by_current_ruby?) }
36
+ ```
37
+
38
+ ##### Utility methods
39
+
40
+ ```ruby
41
+ PV.supported_by_current_ruby?('alpha') # => true
42
+ PV.supported_by_current_ruby?('foobar') # => false
21
43
 
22
44
  # this one takes a second
23
45
  PV.matched_characters('AHex') # => %w[0 1 2 3 4 5 6 7 8 9 A B C ...]
24
46
 
25
- # this one takes a minute
47
+ # this one takes a minute or two
26
48
  PV.alias_hash # => {"M" => "Mark", "Grek" => "Greek", ...}
27
49
 
28
50
  # download the latest list of possible properties
@@ -1,4 +1,5 @@
1
- require "regexp_property_values/version"
1
+ require 'regexp_property_values/value_extension'
2
+ require 'regexp_property_values/version'
2
3
 
3
4
  module RegexpPropertyValues
4
5
  module_function
@@ -20,15 +21,17 @@ module RegexpPropertyValues
20
21
  by_category.values.flatten
21
22
  end
22
23
 
24
+ def all_for_current_ruby
25
+ all.select(&:supported_by_current_ruby?)
26
+ end
27
+
23
28
  def by_category
24
29
  result = File.foreach(file_path).inject({}) do |hash, line|
25
30
  if /^\* (?<category>\S.+)/ =~ line
26
31
  @current_category = category
27
32
  hash[@current_category] ||= []
28
- elsif /^ {4}(?<property>\S.*)/ =~ line
29
- # only include props that are supported by the host ruby version
30
- begin /\p{#{property}}/u; rescue RegexpError, SyntaxError; next hash end
31
- hash[@current_category] << property
33
+ elsif /^ {4}(?<value_name>\S.*)/ =~ line
34
+ hash[@current_category] << value(value_name)
32
35
  end
33
36
  hash
34
37
  end
@@ -36,10 +39,15 @@ module RegexpPropertyValues
36
39
  result
37
40
  end
38
41
 
42
+ def add_oniguruma_properties(props_by_category)
43
+ props_by_category['Special'] << value('Newline')
44
+ end
45
+
39
46
  def alias_hash
40
47
  short_names, long_names = short_and_long_names
41
48
  return {} if short_names.empty?
42
49
 
50
+ long_names -= by_category['POSIX brackets']
43
51
  by_matched_characters.each_value.inject({}) do |hash, props|
44
52
  next hash if props.count < 2
45
53
  long_name = (props & long_names)[0] || fail("no long name for #{props}")
@@ -60,18 +68,19 @@ module RegexpPropertyValues
60
68
 
61
69
  def by_matched_characters
62
70
  puts 'Establishing property characters, this may take a bit ...'
63
- all.group_by { |prop| matched_characters(prop) }
71
+ all.group_by(&:matched_characters)
64
72
  end
65
73
 
66
74
  def matched_characters(prop)
67
- @characters ||= ((0..55_295).to_a + (57_344..1_114_111).to_a)
68
- .map { |cp_number| [cp_number].pack('U') }
69
- prop_regex = /\p{#{prop}}/u
70
- @characters.select { |char| prop_regex.match(char) }
75
+ value(prop).matched_characters
71
76
  end
72
77
 
73
- def add_oniguruma_properties(props_by_category)
74
- return if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0')
75
- props_by_category['Special'] << 'Newline'
78
+ def supported_by_current_ruby?(prop)
79
+ value(prop).supported_by_current_ruby?
80
+ end
81
+
82
+ def value(prop)
83
+ prop.singleton_class.send(:include, ValueExtension)
84
+ prop
76
85
  end
77
86
  end
@@ -0,0 +1,20 @@
1
+ module RegexpPropertyValues
2
+ def self.characters
3
+ @characters ||= ((0..55_295).to_a + (57_344..1_114_111).to_a)
4
+ .map { |cp_number| [cp_number].pack('U') }
5
+ end
6
+
7
+ module ValueExtension
8
+ def supported_by_current_ruby?
9
+ begin !!regexp; rescue RegexpError, SyntaxError; false end
10
+ end
11
+
12
+ def matched_characters
13
+ RegexpPropertyValues.characters.select { |char| regexp.match(char) }
14
+ end
15
+
16
+ def regexp
17
+ @regexp ||= /\p{#{self}}/u
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module RegexpPropertyValues
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regexp_property_values
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Janosch Müller
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2018-05-11 00:00:00.000000000 Z
11
+ date: 2018-05-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.16'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.16'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '10.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '10.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '3.0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '3.0'
62
55
  description: This microlibrary lets you see which property values are supported by
@@ -68,11 +61,10 @@ executables: []
68
61
  extensions: []
69
62
  extra_rdoc_files: []
70
63
  files:
71
- - .gitignore
72
- - .rspec
73
- - .travis.yml
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
74
67
  - Gemfile
75
- - Gemfile.lock
76
68
  - LICENSE.txt
77
69
  - README.md
78
70
  - Rakefile
@@ -80,31 +72,31 @@ files:
80
72
  - bin/setup
81
73
  - lib/UnicodeProps.txt
82
74
  - lib/regexp_property_values.rb
75
+ - lib/regexp_property_values/value_extension.rb
83
76
  - lib/regexp_property_values/version.rb
84
77
  - regexp_property_values.gemspec
85
78
  homepage: https://github.com/janosch-x/regexp_property_values
86
79
  licenses:
87
80
  - MIT
81
+ metadata: {}
88
82
  post_install_message:
89
83
  rdoc_options: []
90
84
  require_paths:
91
85
  - lib
92
86
  required_ruby_version: !ruby/object:Gem::Requirement
93
- none: false
94
87
  requirements:
95
- - - ! '>='
88
+ - - ">="
96
89
  - !ruby/object:Gem::Version
97
90
  version: '0'
98
91
  required_rubygems_version: !ruby/object:Gem::Requirement
99
- none: false
100
92
  requirements:
101
- - - ! '>='
93
+ - - ">="
102
94
  - !ruby/object:Gem::Version
103
95
  version: '0'
104
96
  requirements: []
105
97
  rubyforge_project:
106
- rubygems_version: 1.8.23.2
98
+ rubygems_version: 2.7.6
107
99
  signing_key:
108
- specification_version: 3
100
+ specification_version: 4
109
101
  summary: Lists property values supported by Ruby's regex engine
110
102
  test_files: []
@@ -1,35 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- regexp_property_values (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- diff-lcs (1.3)
10
- rake (10.5.0)
11
- rspec (3.7.0)
12
- rspec-core (~> 3.7.0)
13
- rspec-expectations (~> 3.7.0)
14
- rspec-mocks (~> 3.7.0)
15
- rspec-core (3.7.1)
16
- rspec-support (~> 3.7.0)
17
- rspec-expectations (3.7.0)
18
- diff-lcs (>= 1.2.0, < 2.0)
19
- rspec-support (~> 3.7.0)
20
- rspec-mocks (3.7.0)
21
- diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.7.0)
23
- rspec-support (3.7.1)
24
-
25
- PLATFORMS
26
- ruby
27
-
28
- DEPENDENCIES
29
- bundler (~> 1.16)
30
- rake (~> 10.0)
31
- regexp_property_values!
32
- rspec (~> 3.0)
33
-
34
- BUNDLED WITH
35
- 1.16.1