char_size 0.2.1 → 0.2.2

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: f5ed68db56f43eea742583e0beea346b72c197d6
4
- data.tar.gz: 39050055ae78300950b648c6c1b3cd41a8bef30e
3
+ metadata.gz: 9ff09b048174c469587fd7401ff10443c309a425
4
+ data.tar.gz: 03160e3cdfb739d42c06cedb046c97657f155b10
5
5
  SHA512:
6
- metadata.gz: a2c2ab26b53ab4e848021c35da15996702c8302839ec2b84c16701927f503a75163e6bad390837122278f16d34dae818a45783d2c4c1d6ef389203cc7fd5a8ea
7
- data.tar.gz: 5788bebedae4a24b984da72d8fb7d21b5a82ff514a0276cdf88c859fda4c5e9cc4c17b45a33829beb985e0d10c816aa4d846ed71481c1dcfcfa630ead178a639
6
+ metadata.gz: 0b1d680bc421595c1a61d9a3fa2f35946c5cfa701835af569d9c34a70e9a6a6a2fb4f2c08831645df839b6979b69bb0ea53ce2ac8a41bf6302d1a6ebd439bbc2
7
+ data.tar.gz: d44b11ddb4595c050b6e1b8b8dfc77617fc9ea68d9d1c6448a9f35fefe1b0e5ae84bfcb822e1b100b44914b9f4fcdad2ca6796cc1f0ea3dba63b6fc248335e53
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require "rake/extensiontask"
5
5
  require "rake/testtask"
6
6
  require "yard"
7
7
 
8
- CLEAN.include "lib/char_size/char_size.bundle"
8
+ CLEAN.include("lib/char_size/char_size.#{RbConfig::CONFIG['DLEXT']}")
9
9
 
10
10
  Rake::ExtensionTask.new :char_size, Bundler::GemHelper.gemspec do |ext|
11
11
  ext.lib_dir = "lib/char_size"
@@ -27,9 +27,26 @@ static VALUE max(VALUE class, VALUE encoding_or_name)
27
27
  return INT2NUM(ONIGENC_MBC_MAXLEN(rb_to_encoding(encoding_or_name)));
28
28
  }
29
29
 
30
- void Init_char_size()
30
+ /*
31
+ * Gets the minimum and maximum character size (in bytes) for an encoding.
32
+ * @param encoding_or_name [Encoding, String] the encoding or its name
33
+ * @return [Array<(Integer, Integer)>] the minimum and maximum character size
34
+ * @example
35
+ * CharSize.minmax("UTF-8") # => [1, 6]
36
+ * CharSize.minmax(Encoding::UTF_8) # => [1, 6]
37
+ */
38
+ static VALUE minmax(VALUE class, VALUE encoding_or_name)
39
+ {
40
+ rb_encoding *enc = rb_to_encoding(encoding_or_name);
41
+ VALUE min = INT2NUM(ONIGENC_MBC_MINLEN(enc));
42
+ VALUE max = INT2NUM(ONIGENC_MBC_MAXLEN(enc));
43
+ return rb_assoc_new(min, max);
44
+ }
45
+
46
+ void Init_char_size(void)
31
47
  {
32
48
  VALUE CharSize = rb_define_module("CharSize");
33
49
  rb_define_singleton_method(CharSize, "min", min, 1);
34
50
  rb_define_singleton_method(CharSize, "max", max, 1);
51
+ rb_define_singleton_method(CharSize, "minmax", minmax, 1);
35
52
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CharSize
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
data/lib/char_size.rb CHANGED
@@ -2,17 +2,3 @@
2
2
 
3
3
  require "char_size/char_size"
4
4
  require "char_size/version"
5
-
6
- # The +CharSize+ module provides functions that return the character size limits
7
- # of encodings.
8
- module CharSize
9
- # Gets the minimum and maximum character size (in bytes) for an encoding.
10
- # @param encoding_or_name [Encoding, String] the encoding or its name
11
- # @return [Array<(Integer, Integer)>] the minimum and maximum character size
12
- # @example
13
- # CharSize.minmax("UTF-8") # => [1, 6]
14
- # CharSize.minmax(Encoding::UTF_8) # => [1, 6]
15
- def self.minmax(encoding_or_name)
16
- [min(encoding_or_name), max(encoding_or_name)]
17
- end
18
- 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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Haines