char_size 0.1.2 → 0.2.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: cb2ccbd5b3a1ce968c5c5ed407ca3c8a9a8ca290
4
- data.tar.gz: 5fd162637a1b4bcbdfb9a03ba2a1a45cb89f5033
3
+ metadata.gz: 6828b103b20f4146b1d1dab950c3406ead00ce81
4
+ data.tar.gz: bb140e077caeb3f704a9fa1b599c08891a971c54
5
5
  SHA512:
6
- metadata.gz: f717d585dad3ce6944ba19fbcf9b3e3caa8be7d3fae82df9629b11154750250a5879b9dbc770bedca776a7bbe4c46380066bcb8c4e53f4bb6a40260ab1244391
7
- data.tar.gz: 123811b647439497874155057078df2cc5754f6f1e6b709a7113f7ab18e2a8ee4d0ec135b3a0dcd9b02477b24ba759fc4f3f8645ad6b5058dddfc04d222141ea
6
+ metadata.gz: 36fc67ddacafe8ee708b52dded407224dd5c9126e8ef3608b66ae6022f85ee9a50eedafcefab021c82baaa44a01ab3398d5b4ff3144720f0a722aff561c650f4
7
+ data.tar.gz: eeb92cc7a3322cb1363aba9a5416d1ba1227e509691874042de5ced26a79a973774506bd7c47fb3fd48ea3fd409bcde6148af6d4a463347ad7e8821bc6d71071
@@ -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)->min_enc_len);
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)->max_enc_len);
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CharSize
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.2
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: