char_size 0.1.2 → 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.
- checksums.yaml +4 -4
- data/ext/char_size/char_size.c +2 -2
- data/lib/char_size/rake/char_size.rb.erb +27 -0
- data/lib/char_size/rake/generator_task.rb +59 -0
- data/lib/char_size/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6828b103b20f4146b1d1dab950c3406ead00ce81
|
4
|
+
data.tar.gz: bb140e077caeb3f704a9fa1b599c08891a971c54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36fc67ddacafe8ee708b52dded407224dd5c9126e8ef3608b66ae6022f85ee9a50eedafcefab021c82baaa44a01ab3398d5b4ff3144720f0a722aff561c650f4
|
7
|
+
data.tar.gz: eeb92cc7a3322cb1363aba9a5416d1ba1227e509691874042de5ced26a79a973774506bd7c47fb3fd48ea3fd409bcde6148af6d4a463347ad7e8821bc6d71071
|
data/ext/char_size/char_size.c
CHANGED
@@ -15,7 +15,7 @@ static rb_encoding* find_encoding(VALUE encoding_or_name) {
|
|
15
15
|
* CharSize.min(Encoding::UTF_8) # => 1
|
16
16
|
*/
|
17
17
|
static VALUE min(VALUE class, VALUE encoding_or_name) {
|
18
|
-
return INT2NUM(find_encoding(encoding_or_name)
|
18
|
+
return INT2NUM(ONIGENC_MBC_MINLEN(find_encoding(encoding_or_name)));
|
19
19
|
}
|
20
20
|
|
21
21
|
/*
|
@@ -27,7 +27,7 @@ static VALUE min(VALUE class, VALUE encoding_or_name) {
|
|
27
27
|
* CharSize.max(Encoding::UTF_8) # => 6
|
28
28
|
*/
|
29
29
|
static VALUE max(VALUE class, VALUE encoding_or_name) {
|
30
|
-
return INT2NUM(find_encoding(encoding_or_name)
|
30
|
+
return INT2NUM(ONIGENC_MBC_MAXLEN(find_encoding(encoding_or_name)));
|
31
31
|
}
|
32
32
|
|
33
33
|
void Init_char_size() {
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This module was generated using the CharSize gem.
|
4
|
+
# To regenerate, run
|
5
|
+
# rake <%= @task_name %>
|
6
|
+
module CharSize
|
7
|
+
CHAR_SIZES = {
|
8
|
+
<%=
|
9
|
+
Encoding.list.map { |encoding|
|
10
|
+
"#{encoding.name.inspect} => #{CharSize.minmax(encoding).inspect}.freeze"
|
11
|
+
}.join(",\n ")
|
12
|
+
%>
|
13
|
+
}.freeze
|
14
|
+
private_constant :CHAR_SIZES
|
15
|
+
|
16
|
+
def self.min(encoding_or_name)
|
17
|
+
minmax(encoding_or_name).first
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.max(encoding_or_name)
|
21
|
+
minmax(encoding_or_name).last
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.minmax(encoding_or_name)
|
25
|
+
CHAR_SIZES.fetch(Encoding.find(encoding_or_name).name)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "char_size"
|
4
|
+
require "erb"
|
5
|
+
require "rake"
|
6
|
+
require "rake/tasklib"
|
7
|
+
|
8
|
+
module CharSize
|
9
|
+
module Rake
|
10
|
+
# A Rake task to generate a static copy of the {CharSize} module.
|
11
|
+
# This means that the +char_size+ gem can be used as a development dependency rather than a runtime dependency.
|
12
|
+
class GeneratorTask < ::Rake::TaskLib
|
13
|
+
# The name of the task. Defaults to +:char_size+.
|
14
|
+
# @return [String, Symbol] the task name
|
15
|
+
attr_accessor :name
|
16
|
+
|
17
|
+
# The path of the generated file. Defaults to +"lib/char_size.rb"+.
|
18
|
+
# @return [String] the file path
|
19
|
+
attr_accessor :destination
|
20
|
+
|
21
|
+
# Defines a new {CharSize} module generator task.
|
22
|
+
# @param name [String, Symbol] the name of the task
|
23
|
+
# @yield [self] allowing any options to be modified on the task
|
24
|
+
def initialize(name = :char_size)
|
25
|
+
@name = name
|
26
|
+
@destination = "lib/char_size.rb"
|
27
|
+
|
28
|
+
yield self if block_given?
|
29
|
+
|
30
|
+
define
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def define
|
36
|
+
desc "Generate static CharSize module" unless ::Rake.application.last_description
|
37
|
+
task(name) do |task|
|
38
|
+
FileUtils.mkdir_p File.dirname(destination)
|
39
|
+
File.write destination, template.result(assigns(task).instance_eval { binding })
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def template
|
44
|
+
ERB.new(File.read(File.expand_path("char_size.rb.erb", __dir__)))
|
45
|
+
end
|
46
|
+
|
47
|
+
def assigns(task)
|
48
|
+
Assigns.new(task_name: task.name)
|
49
|
+
end
|
50
|
+
|
51
|
+
class Assigns
|
52
|
+
def initialize(task_name:)
|
53
|
+
@task_name = task_name
|
54
|
+
end
|
55
|
+
end
|
56
|
+
private_constant :Assigns
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/char_size/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: char_size
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Haines
|
@@ -132,6 +132,8 @@ files:
|
|
132
132
|
- ext/char_size/char_size.h
|
133
133
|
- ext/char_size/extconf.rb
|
134
134
|
- lib/char_size.rb
|
135
|
+
- lib/char_size/rake/char_size.rb.erb
|
136
|
+
- lib/char_size/rake/generator_task.rb
|
135
137
|
- lib/char_size/version.rb
|
136
138
|
homepage: https://github.com/haines/char_size
|
137
139
|
licenses:
|