unicode-display_width 0.2.0 → 0.3.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: 5058b7809dc89b3b1e3bdefa2e1841ea5b002756
4
- data.tar.gz: 95846a31cad8bd25a2c3e4b59ff500b8872f27b3
3
+ metadata.gz: 0b600c9e8b63a894f3949dbc550fcc36f9954d9e
4
+ data.tar.gz: 7a91242b996b77192f59da5ca4bcce96f3d15d7e
5
5
  SHA512:
6
- metadata.gz: f65fb25b23a4823c2227d95cd47b5d3d78839013c1ec007702a36ac7ac0c02e716292db08d295c9c706ed478e77254fce1224f2fb7132a7f5ae5af9750cc5993
7
- data.tar.gz: da457ce61a13d12ca3aa753f87dcc0899a70589e24ecf50ec5385be3ee93bfbb39af37462635c09f63cbd82bf9fd0d5cc4aa29689560cd730e8641952d9242ed
6
+ metadata.gz: dee920064581a08e71a0bf4867096191f8f9c6811b6e3616836c19715d899748c4c7f180df1ae09a699fa537b440f30f32d294d44621e9628706bc06c9ad6fcc
7
+ data.tar.gz: 5160acd691a9bd65f05915f3f4a051baa2d1457d8d2b3f1d1ce2cedfa41cf3eeddddf3ee85e80abe93ddaeba0e86c519ecc4279a614cce2e788b69021d4645c4
@@ -1,3 +1,10 @@
1
+ ## 0.3.0
2
+ * Update EastAsianWidth from 7.0 to 8.0
3
+ * Add rake task to update EastAsianWidth.txt
4
+ * Move code to generate index from library to Rakefile
5
+ * Update project's meta files
6
+ * Deprecate requiring 'unicode-display_size'
7
+
1
8
  ## 0.2.0
2
9
 
3
10
  * Update EastAsianWidth from 6.0 to 7.0
File without changes
@@ -4,24 +4,28 @@ An early draft of a way to determine the size of the characters using <tt>EastAs
4
4
 
5
5
  == Install
6
6
 
7
- Install the gem with
7
+ Install the gem with:
8
8
 
9
9
  gem install unicode-display_width
10
10
 
11
+ or add to your Gemfile:
12
+
13
+ gem 'unicode-display_width'
14
+
11
15
  == Usage
12
16
 
13
17
  require 'unicode/display_width'
14
18
 
15
- The easy way is to use the String#display_size method:
19
+ The easy way is to use the <tt>String#display_width</tt> method:
16
20
  "⚀".display_width #=> 1
17
21
  '一'.display_width #=> 2
18
22
 
19
23
  To obtain more detailed character data, you can use the following syntax:
20
24
  Unicode::DisplayWidth.codepoint( c )
21
25
 
22
- === Ambigous Characters
26
+ === Ambiguous Characters
23
27
 
24
- The display_width method takes an optional argument, which will be used as width for characters defined as "ambigious". The default value is 1.
28
+ The <tt>display_width</tt> method takes an optional argument, which will be used as width for characters defined as "ambigious". The default value is 1.
25
29
 
26
30
  == Copyright
27
31
 
@@ -29,6 +33,6 @@ Copyright (c) 2011, 2015 Jan Lelis, http://rbjl.net, released under the MIT lice
29
33
 
30
34
  Contains code by runpaint: Copyright (c) 2009 Run Paint Run Run
31
35
 
32
- Contains EastAsianWidth.txt: Copyright (c) 1991-2014 Unicode, Inc.
36
+ Contains EastAsianWidth.txt: Copyright (c) 1991-2015 Unicode, Inc.
33
37
 
34
38
  J-_-L
data/Rakefile CHANGED
@@ -1,35 +1,84 @@
1
- require 'rake'
2
- require 'fileutils'
1
+ # # #
2
+ # Get gemspec info
3
3
 
4
- def gemspec
5
- @gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
6
- end
4
+ gemspec_file = Dir['*.gemspec'].first
5
+ gemspec = eval File.read(gemspec_file), binding, gemspec_file
6
+ info = "#{gemspec.name} | #{gemspec.version} | " \
7
+ "#{gemspec.runtime_dependencies.size} dependencies | " \
8
+ "#{gemspec.files.size} files"
9
+
10
+
11
+ # # #
12
+ # Gem build and install task
7
13
 
8
- desc "Build the gem"
9
- task :gem=>:gemspec do
10
- sh "gem build .gemspec"
14
+ desc info
15
+ task :gem do
16
+ puts info + "\n\n"
17
+ print " "; sh "gem build #{gemspec_file}"
11
18
  FileUtils.mkdir_p 'pkg'
12
19
  FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
20
+ puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
13
21
  end
14
22
 
15
- desc "Install the gem locally"
16
- task :install => :gem do
17
- sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}.gem}
23
+
24
+ # # #
25
+ # Start an IRB session with the gem loaded
26
+
27
+ desc "#{gemspec.name} | IRB"
28
+ task :irb do
29
+ sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
18
30
  end
19
31
 
20
- desc "Generate the gemspec"
21
- task :generate do
22
- puts gemspec.to_ruby
32
+ # # #
33
+ # Run all specs
34
+
35
+
36
+ desc "#{gemspec.name} | Test"
37
+ task :test do
38
+ sh "rspec spec"
23
39
  end
40
+ task :default => :test
41
+
42
+ # # #
43
+ # Update index table
24
44
 
25
- desc "Validate the gemspec"
26
- task :gemspec do
27
- gemspec.validate
45
+ namespace :update do
46
+ desc "#{gemspec.name} | Update index"
47
+ task :index do
48
+ require File.dirname(__FILE__) + '/lib/unicode/display_width'
49
+ data = File.open Unicode::DisplayWidth::DATA_FILE
50
+ data.rewind
51
+ table = {}
52
+ dir = File.dirname Unicode::DisplayWidth::TABLE_FILE
53
+ Dir.mkdir(dir) unless Dir.exists?(dir)
54
+ data.each_line{ |line|
55
+ line =~ /^(\S+?);(\S+)\s+#.*$/
56
+ if $1 && $2
57
+ cps, width = $1, $2
58
+ if cps['..']
59
+ range = Range.new *cps.split('..').map{ |cp| cp.to_i(16) }
60
+ range.each{ |cp| table[ cp ] = width.to_sym }
61
+ else
62
+ table[ cps.to_i(16) ] = width.to_sym
63
+ end
64
+ end
65
+
66
+ }
67
+ File.open(Unicode::DisplayWidth::TABLE_FILE, 'wb') { |f| Marshal.dump(table, f) }
68
+ end
28
69
  end
29
70
 
30
- desc 'Run tests'
31
- task :test do |t|
32
- sh 'rspec'
71
+ # # #
72
+ # Update data file
73
+
74
+ namespace :update do
75
+ desc "#{gemspec.name} | Update unicode data"
76
+ task :data do
77
+ require File.dirname(__FILE__) + '/lib/unicode/display_width'
78
+ require 'open-uri'
79
+ open("http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt") { |f|
80
+ File.write(Unicode::DisplayWidth::DATA_FILE, f.read)
81
+ }
82
+ end
33
83
  end
34
84
 
35
- task :default => :test
Binary file
@@ -1 +1,2 @@
1
+ warn "Deprecation warning: Please use require 'unicode/display_width' instead of require 'unicode/display_size'"
1
2
  require File.dirname(__FILE__) + "/display_width"
@@ -1,61 +1,31 @@
1
1
  # encoding: utf-8
2
- module Unicode; end
3
- module Unicode::DisplayWidth
4
- VERSION = '0.2.0'
5
- end
6
-
7
-
8
- class << Unicode::DisplayWidth
9
- DATA_DIR = File.join(File.dirname(__FILE__), '../../data/')
10
- TABLE_FILE = DATA_DIR + 'EastAsianWidth.index'
11
- DATA_FILE = DATA_DIR + 'EastAsianWidth.txt'
12
-
13
- # # # lookup
14
-
15
- def table
16
- if @table
17
- @table
18
- else
19
- @table = Marshal.load File.respond_to?(:binread) ? File.binread(TABLE_FILE) : File.read(TABLE_FILE)
20
- end
21
- end
22
-
23
- def codepoint(n)
24
- n = n.to_s.unpack('U')[0] unless n.is_a? Integer
25
- table[n] or raise ArgumentError, 'codepoint not found'
26
- end
27
- alias width codepoint
28
- alias of codepoint
29
-
30
2
 
31
- # # # index
32
-
33
- def build_table
34
- data = File.open DATA_FILE
35
- data.rewind
36
- table = {}
37
- dir = File.dirname TABLE_FILE
38
- Dir.mkdir(dir) unless Dir.exists?(dir)
39
- data.each_line{ |line|
40
- line =~ /^(\S+?);(\S+)\s+#.*$/
41
- if $1 && $2
42
- cps, width = $1, $2
43
- if cps['..']
44
- range = Range.new *cps.split('..').map{ |cp| cp.to_i(16) }
45
- range.each{ |cp| table[ cp ] = width.to_sym }
3
+ module Unicode
4
+ module DisplayWidth
5
+ VERSION = '0.3.0'.freeze
6
+ DATA_DIR = File.join(File.dirname(__FILE__), '../../data/').freeze
7
+ TABLE_FILE = (DATA_DIR + 'EastAsianWidth.index').freeze
8
+ DATA_FILE = (DATA_DIR + 'EastAsianWidth.txt').freeze
9
+
10
+ class << self
11
+ def table
12
+ if @table
13
+ @table
46
14
  else
47
- table[ cps.to_i(16) ] = width.to_sym
15
+ @table = Marshal.load File.respond_to?(:binread) ? File.binread(TABLE_FILE) : File.read(TABLE_FILE)
48
16
  end
49
17
  end
50
18
 
51
- }
52
- File.open(TABLE_FILE, 'wb') { |f| Marshal.dump(table, f) }
19
+ def codepoint(n)
20
+ n = n.to_s.unpack('U')[0] unless n.is_a? Integer
21
+ table[n] or raise ArgumentError, 'codepoint not found'
22
+ end
23
+ alias width codepoint
24
+ alias of codepoint
25
+ end
53
26
  end
54
27
  end
55
28
 
56
-
57
- # # # core ext
58
-
59
29
  class String
60
30
  def display_width(ambiguous = 1)
61
31
  unpack('U*').inject(0){ |a,c|
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
11
11
  s.summary = "Support for east_asian_width string widths."
12
12
  s.description = "This gem adds String#display_size to get the display size of a string using EastAsianWidth.txt."
13
13
  s.required_rubygems_version = ">= 1.3.6"
14
- s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} data/EastAsianWidth.index ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
15
- s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt", "CHANGELOG.txt"]
14
+ s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} data/EastAsianWidth.index ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile unicode-display_width.gemspec}
15
+ s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE.txt", "CHANGELOG.txt"]
16
16
  s.license = 'MIT'
17
17
  s.add_development_dependency 'rspec', '~> 3.2'
18
18
  s.add_development_dependency 'rake', '~> 10.4'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unicode-display_width
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -45,17 +45,17 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files:
47
47
  - README.rdoc
48
- - LICENSE.txt
48
+ - MIT-LICENSE.txt
49
49
  - CHANGELOG.txt
50
50
  files:
51
- - ".gemspec"
52
51
  - CHANGELOG.txt
53
- - LICENSE.txt
52
+ - MIT-LICENSE.txt
54
53
  - README.rdoc
55
54
  - Rakefile
56
55
  - data/EastAsianWidth.index
57
56
  - lib/unicode/display_size.rb
58
57
  - lib/unicode/display_width.rb
58
+ - unicode-display_width.gemspec
59
59
  homepage: http://github.com/janlelis/unicode-display_width
60
60
  licenses:
61
61
  - MIT
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: 1.3.6
77
77
  requirements: []
78
78
  rubyforge_project:
79
- rubygems_version: 2.4.5
79
+ rubygems_version: 2.4.6
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Support for east_asian_width string widths.