unicode-name 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 661337ed0ad17a4c57245aebb540a70e9c3cd348
4
- data.tar.gz: 7906428802e6fe31f8718b99ebf0d655558e1410
3
+ metadata.gz: f3a8de48e9b0cde71e28b66a905775a415258861
4
+ data.tar.gz: ce9bb0b4e85c1b456ae79a62287ce0e48e4ba238
5
5
  SHA512:
6
- metadata.gz: 6088029d191d4d4e3320a60e7603dd9a9467725b1c44d893063ed23a94cc7ba2a14348679664a211a8c5f5e2b0a6aa402d32822bcfa28e3c75443daf5cfb3626
7
- data.tar.gz: a5b4076597eb6dc9a3e84066906256aa1ac214728c88293ea33aef7d02b79db15554d85f187b5f51af2075ff9daf74c6ea29e52df9494c23e18707ab6a1f5278
6
+ metadata.gz: 97265bf800a36c2207ae3e2bb74d24473ed91f399e726ae5e1136eacbbdf16be87007fd5fc277f3d0024e339f8c80adfc4c22160fc862c5bcb4a6bfb96b2e68e
7
+ data.tar.gz: 2a140e46907de2e489279970763b49d5b9ec87059b621af60338835ca69fec7097a02550ccd8d25c778e0ac8678cab38af04f36f681e4c293e1a35212d2e56b7
@@ -1,5 +1,9 @@
1
1
  ## CHANGELOG
2
2
 
3
+ ### 1.1.0
4
+
5
+ * Support codepoint labels
6
+
3
7
  ### 1.0.0
4
8
 
5
9
  * Inital release
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Unicode::Name [![[version]](https://badge.fury.io/rb/unicode-name.svg)](http://badge.fury.io/rb/unicode-name) [![[travis]](https://travis-ci.org/janlelis/unicode-name.png)](https://travis-ci.org/janlelis/unicode-name)
2
2
 
3
- Return Unicode character names and aliases.
3
+ Return Unicode codepoint names, aliases, and labels.
4
4
 
5
5
  Unicode version: **8.0.0**
6
6
 
@@ -22,8 +22,21 @@ Unicode::Name.aliases "\t" # => {:control=>["CHARACTER TABULATION", "HORIZONTAL
22
22
  # Corrections (via .aliases[:correction], then name)
23
23
  Unicode::Name.correct "A" # => "LATIN CAPITAL LETTER A"
24
24
  Unicode::Name.correct "Ƣ" # => "LATIN CAPITAL LETTER GHA"
25
+
26
+ # Codepoint labels
27
+ Unicode::Name.label("\0") # => "<control-0000>"
28
+ Unicode::Name.label("\u{D800}") # => "<surrogate-D800>"
29
+ Unicode::Name.label("\u{FFFFF}") # => "<noncharacter-FFFFF>"
30
+ Unicode::Name.label("\u{10C50}") # => "<reserved-10C50>"
31
+
32
+ # Best readable representation
33
+ Unicode::Name.readable("A") # => "LATIN CAPITAL LETTER A"
34
+ Unicode::Name.readable("\0") # => "NULL"
35
+ Unicode::Name.readable("\u{FFFFD}") # => "<private-use-FFFFD>"
25
36
  ```
26
37
 
38
+ See [unicode-x](https://github.com/janlelis/unicode-x) for more Unicode related micro libraries.
39
+
27
40
  ## MIT License
28
41
 
29
42
  - Copyright (C) 2016 Jan Lelis <http://janlelis.com>. Released under the MIT license.
@@ -26,12 +26,11 @@ module Unicode
26
26
  INDEX[:ALIASES][codepoint]
27
27
  end
28
28
 
29
- =begin
30
29
  def self.label(char)
31
30
  codepoint = char.unpack("U")[0]
32
- codepoint_pretty = codepoint.to_s(16).upcase
31
+ codepoint_pretty = "%.4X" % codepoint
33
32
  require_relative "name/index" unless defined? ::Unicode::Name::INDEX
34
- require "unicode/types/index" unless defined? ::Unicode::Types::INDEX
33
+ require "unicode/types" unless defined? ::Unicode::Types
35
34
  case Unicode::Types.type(char)
36
35
  when "Graphic", "Format"
37
36
  nil
@@ -47,7 +46,6 @@ module Unicode
47
46
  "<reserved-#{codepoint_pretty}>"
48
47
  end
49
48
  end
50
- =end
51
49
 
52
50
  def self.readable(char)
53
51
  unicode_name(char) ||
@@ -55,8 +53,8 @@ module Unicode
55
53
  ( as[:control] && as[:control][0] ||
56
54
  as[:figment] && as[:figment][0] ||
57
55
  as[:alternate] && as[:alternate][0] ||
58
- as[:abbreviation] && as[:abbreviation][0] ) #||
59
- # label(char)
56
+ as[:abbreviation] && as[:abbreviation][0] ) ||
57
+ label(char)
60
58
  end
61
59
  end
62
60
  end
@@ -1,6 +1,6 @@
1
1
  module Unicode
2
2
  module Name
3
- VERSION = "1.0.0".freeze
3
+ VERSION = "1.1.0".freeze
4
4
  UNICODE_VERSION = "8.0.0".freeze
5
5
  DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) + '/../../../data/').freeze
6
6
  INDEX_FILENAME = (DATA_DIRECTORY + '/name.marshal.gz').freeze
@@ -39,5 +39,41 @@ describe Unicode::Name do
39
39
  assert_equal ["NUL"], Unicode::Name.aliases("\0")[:abbreviation]
40
40
  end
41
41
  end
42
+
43
+ describe ".label" do
44
+ it "will return nil for usual (graphic) characters" do
45
+ assert_equal nil, Unicode::Name.label("A")
46
+ end
47
+
48
+ it "will return <control-hhhh> for control characters" do
49
+ assert_equal "<control-0000>", Unicode::Name.label("\0")
50
+ end
51
+
52
+ it "will return <private-use> for private use characters" do
53
+ assert_equal "<private-use-FFFFD>", Unicode::Name.label("\u{FFFFD}")
54
+ end
55
+
56
+ it "will return <surrogate-hhhh> for codepoints in surrogate area" do
57
+ assert_equal "<surrogate-D800>", Unicode::Name.label("\u{D800}")
58
+ end
59
+
60
+ it "will return <noncharacter-hhhh> for codepoints defined as noncharacter" do
61
+ assert_equal "<noncharacter-FFFFF>", Unicode::Name.label("\u{FFFFF}")
62
+ end
63
+
64
+ it "will return <reserved-hhhh> for unassigned codepoints" do
65
+ assert_equal "<reserved-10C50>", Unicode::Name.label("\u{10C50}")
66
+ end
67
+ end
68
+
69
+ describe ".readable" do
70
+ it "will return best readable representation of a codepoint" do
71
+ assert_equal "LATIN CAPITAL LETTER A", Unicode::Name.readable("A")
72
+ assert_equal "NULL", Unicode::Name.readable("\0")
73
+ assert_equal "<noncharacter-FFFFF>", Unicode::Name.readable("\u{FFFFF}")
74
+ assert_equal "<reserved-10C50>", Unicode::Name.readable("\u{10C50}")
75
+ assert_equal "<private-use-FFFFD>", Unicode::Name.readable("\u{FFFFD}")
76
+ end
77
+ end
42
78
  end
43
79
 
@@ -5,8 +5,8 @@ require File.dirname(__FILE__) + "/lib/unicode/name/constants"
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "unicode-name"
7
7
  gem.version = Unicode::Name::VERSION
8
- gem.summary = "Returns the name and aliases of a Unicode codepoint/character"
9
- gem.description = "[Unicode version: #{Unicode::Name::UNICODE_VERSION}] Returns the name and aliases of a Unicode codepoint/character"
8
+ gem.summary = "Returns name/aliases/label of a Unicode codepoint"
9
+ gem.description = "[Unicode version: #{Unicode::Name::UNICODE_VERSION}] Returns name/aliases/label of a Unicode codepoint"
10
10
  gem.authors = ["Jan Lelis"]
11
11
  gem.email = ["mail@janlelis.de"]
12
12
  gem.homepage = "https://github.com/janlelis/unicode-name"
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.required_ruby_version = "~> 2.0"
21
+ gem.add_dependency "unicode-types", "~> 1.0", ">= 1.0.1"
21
22
  end
metadata CHANGED
@@ -1,16 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unicode-name
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Lelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
12
- dependencies: []
13
- description: "[Unicode version: 8.0.0] Returns the name and aliases of a Unicode codepoint/character"
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: unicode-types
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.1
33
+ description: "[Unicode version: 8.0.0] Returns name/aliases/label of a Unicode codepoint"
14
34
  email:
15
35
  - mail@janlelis.de
16
36
  executables: []
@@ -30,7 +50,6 @@ files:
30
50
  - lib/unicode/name/constants.rb
31
51
  - lib/unicode/name/index.rb
32
52
  - lib/unicode/name/string_ext.rb
33
- - spec/.unicode_name_spec.rb.swp
34
53
  - spec/unicode_name_spec.rb
35
54
  - unicode-name.gemspec
36
55
  homepage: https://github.com/janlelis/unicode-name
@@ -56,8 +75,7 @@ rubyforge_project:
56
75
  rubygems_version: 2.6.3
57
76
  signing_key:
58
77
  specification_version: 4
59
- summary: Returns the name and aliases of a Unicode codepoint/character
78
+ summary: Returns name/aliases/label of a Unicode codepoint
60
79
  test_files:
61
- - spec/.unicode_name_spec.rb.swp
62
80
  - spec/unicode_name_spec.rb
63
81
  has_rdoc: