unicode-numeric_value 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ # # #
2
+ # Get gemspec info
3
+
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
+ # Gem build and install task
12
+
13
+ desc info
14
+ task :gem do
15
+ puts info + "\n\n"
16
+ print " "; sh "gem build #{gemspec_file}"
17
+ FileUtils.mkdir_p 'pkg'
18
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
19
+ puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
20
+ end
21
+
22
+ # # #
23
+ # Start an IRB session with the gem loaded
24
+
25
+ desc "#{gemspec.name} | IRB"
26
+ task :irb do
27
+ sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
28
+ end
29
+
30
+ # # #
31
+ # Run Specs
32
+
33
+ desc "#{gemspec.name} | Spec"
34
+ task :spec do
35
+ sh "for file in spec/*.rb; do ruby $file; done"
36
+ end
37
+ task default: :spec
@@ -0,0 +1,19 @@
1
+ require_relative "numeric_value/constants"
2
+
3
+ module Unicode
4
+ module NumericValue
5
+ def self.numeric_value(char)
6
+ codepoint = char.unpack("U")[0] or
7
+ raise(ArgumentError, "Unicode::NumericValue.numeric_value must be given a valid char")
8
+ require_relative "numeric_value/index" unless defined? ::Unicode::NumericValue::INDEX
9
+ INDEX[codepoint]
10
+ end
11
+ class << self; alias of numeric_value; end
12
+
13
+ def self.chars
14
+ require_relative "numeric_value/index" unless defined? ::Unicode::NumericValue::INDEX
15
+ INDEX.keys.map{ |codepoint| [codepoint].pack("U") }
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,9 @@
1
+ module Unicode
2
+ module NumericValue
3
+ VERSION = "1.0.0".freeze
4
+ UNICODE_VERSION = "8.0.0".freeze
5
+ DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) + '/../../../data/').freeze
6
+ INDEX_FILENAME = (DATA_DIRECTORY + '/numeric_value.marshal.gz').freeze
7
+ end
8
+ end
9
+
@@ -0,0 +1,7 @@
1
+ require_relative 'constants'
2
+
3
+ module Unicode
4
+ module NumericValue
5
+ INDEX = Marshal.load(Gem.gunzip(File.binread(INDEX_FILENAME)))
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require_relative "../numeric_value"
2
+
3
+ class String
4
+ # Optional string extension for your convenience
5
+ def numeric_value
6
+ Unicode::NumericValue.of(self)
7
+ end
8
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "../lib/unicode/numeric_value"
2
+ require "minitest/autorun"
3
+
4
+ describe Unicode::NumericValue do
5
+ describe ".numeric_value (alias .of)" do
6
+ it "will return integers values" do
7
+ assert_equal 1, Unicode::NumericValue.of("1")
8
+ assert_equal 8, Unicode::NumericValue.of("Ⅷ")
9
+ assert_equal 19, Unicode::NumericValue.of("⓳")
10
+ assert_equal 1000000000000, Unicode::NumericValue.of("𖭡")
11
+ end
12
+
13
+ it "will return rational values" do
14
+ assert_equal 3/4r, Unicode::NumericValue.of("¾")
15
+ assert_equal -1/2r, Unicode::NumericValue.of("༳")
16
+ end
17
+
18
+ it "will return nil if no numeric value associated" do
19
+ assert_equal nil, Unicode::NumericValue.of("A")
20
+ assert_equal nil, Unicode::NumericValue.of("\0")
21
+ end
22
+ end
23
+
24
+ describe ".chars" do
25
+ it "will return all characters that have an numerical value" do
26
+ assert_equal true, Unicode::NumericValue.chars.include?("⑸")
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + "/lib/unicode/numeric_value/constants"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "unicode-numeric_value"
7
+ gem.version = Unicode::NumericValue::VERSION
8
+ gem.summary = "Convert a Unicode character into its numeric value."
9
+ gem.description = "[Unicode #{Unicode::NumericValue::UNICODE_VERSION}] Convert a Unicode character into its numeric value."
10
+ gem.authors = ["Jan Lelis"]
11
+ gem.email = ["mail@janlelis.de"]
12
+ gem.homepage = "https://github.com/janlelis/unicode-numeric_value"
13
+ gem.license = "MIT"
14
+
15
+ gem.files = Dir["{**/}{.*,*}"].select{ |path| File.file?(path) && path !~ /^pkg/ }
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.required_ruby_version = "~> 2.0"
21
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unicode-numeric_value
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jan Lelis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: "[Unicode 8.0.0] Convert a Unicode character into its numeric value."
14
+ email:
15
+ - mail@janlelis.de
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - MIT-LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - data/numeric_value.marshal.gz
30
+ - lib/unicode/numeric_value.rb
31
+ - lib/unicode/numeric_value/constants.rb
32
+ - lib/unicode/numeric_value/index.rb
33
+ - lib/unicode/numeric_value/string_ext.rb
34
+ - spec/unicode_numeric_value_spec.rb
35
+ - unicode-numeric_value.gemspec
36
+ homepage: https://github.com/janlelis/unicode-numeric_value
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.6.3
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Convert a Unicode character into its numeric value.
60
+ test_files:
61
+ - spec/unicode_numeric_value_spec.rb
62
+ has_rdoc: