char_size 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c15bd99804447ed34ade8c76051223166feeec5
4
- data.tar.gz: 7149b10a8e4b952272887ab83b306a75e45c6620
3
+ metadata.gz: deb464d4821edb234ea24d84c4e988eec0406ad1
4
+ data.tar.gz: 9f8c6ddf01450debbb369e16685802c8509c2ea5
5
5
  SHA512:
6
- metadata.gz: 1f827beef09e6fde3f5d74a1fa61f31408b7d2b1f329e925265dca04f1b55650d6113ed65ad4090291610c92d22d744bbc816bf0adf520494c6eca924c13214b
7
- data.tar.gz: 2117d8af213214aeccc65138bd30b594982f3739cd02ec203810bfee61b8c8e367bdaa0a7b64a81ff9911af50ad40966c35044c4a57ffbb95fee4f00de71e73a
6
+ metadata.gz: e5800463806ea30caa0520a4d8f63a18920b43ec03dd821751a0bc0969a62fc69c09dd4f5aba335c328c9286668c5f832fb4c63531b232a02caa6679fbf05ebb
7
+ data.tar.gz: 9f0fe4db8706c3484d97e9f74fc90b6665c4f2f3a4b5934282f404f2a62dccf9cf13656ec2ac32d58326210d5c044e0e92e1f381ec3f4e13b3fe0815b4cd57d0
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # CharSize
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/char_size.svg)](http://github.com/haines/char_size/releases)
3
4
  [![Build Status](https://travis-ci.org/haines/char_size.svg?branch=master)](https://travis-ci.org/haines/char_size)
4
5
  [![Code Climate](https://codeclimate.com/github/haines/char_size/badges/gpa.svg)](https://codeclimate.com/github/haines/char_size)
5
6
 
6
7
  Find an encoding's minimum and maximum character size.
7
8
 
9
+
8
10
  ## Installation
9
11
 
10
12
  Add this line to your application's Gemfile:
@@ -15,15 +17,27 @@ gem "char_size"
15
17
 
16
18
  And then execute:
17
19
 
18
- $ bundle
20
+ ```console
21
+ $ bundle
22
+ ```
19
23
 
20
24
  Or install it yourself as:
21
25
 
22
- $ gem install char_size
26
+ ```console
27
+ $ gem install char_size
28
+ ```
29
+
23
30
 
24
31
  ## Usage
25
32
 
26
- TODO: Write usage instructions here
33
+ ```ruby
34
+ CharSize.min("UTF-8") # => 1
35
+ CharSize.max("UTF-8") # => 6
36
+ CharSize.minmax("UTF-8") # => [1, 6]
37
+ ```
38
+
39
+ Like `Encoding.find`, methods take a string encoding name, or an instance of `Encoding`.
40
+
27
41
 
28
42
  ## Development
29
43
 
@@ -31,6 +45,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
31
45
 
32
46
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
47
 
48
+
34
49
  ## Contributing
35
50
 
36
51
  Bug reports and pull requests are welcome on GitHub at https://github.com/haines/char_size. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/Rakefile CHANGED
@@ -3,6 +3,7 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "rake/extensiontask"
5
5
  require "rake/testtask"
6
+ require "yard"
6
7
 
7
8
  CLEAN.include "lib/char_size/char_size.bundle"
8
9
 
@@ -15,4 +16,6 @@ Rake::TestTask.new :test do |t|
15
16
  t.warning = true
16
17
  end
17
18
 
19
+ YARD::Rake::YardocTask.new
20
+
18
21
  task :default => [:compile, :test]
data/char_size.gemspec CHANGED
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "pry", "~> 0.10"
28
28
  spec.add_development_dependency "rake", "~> 12.0"
29
29
  spec.add_development_dependency "rake-compiler", "~> 1.0"
30
+ spec.add_development_dependency "yard", "~> 0.9"
30
31
  end
@@ -6,10 +6,26 @@ static rb_encoding* find_encoding(VALUE encoding_or_name) {
6
6
  return encoding;
7
7
  }
8
8
 
9
+ /*
10
+ * Gets the minimum character size (in bytes) for an encoding.
11
+ * @param encoding_or_name [Encoding, String] the encoding or its name
12
+ * @return [Integer] the minimum character size
13
+ * @example
14
+ * CharSize.min("UTF-8") # => 1
15
+ * CharSize.min(Encoding::UTF_8) # => 1
16
+ */
9
17
  static VALUE min(VALUE class, VALUE encoding_or_name) {
10
18
  return INT2NUM(find_encoding(encoding_or_name)->min_enc_len);
11
19
  }
12
20
 
21
+ /*
22
+ * Gets the maximum character size (in bytes) for an encoding.
23
+ * @param encoding_or_name [Encoding, String] the encoding or its name
24
+ * @return [Integer] the minimum character size
25
+ * @example
26
+ * CharSize.max("UTF-8") # => 6
27
+ * CharSize.max(Encoding::UTF_8) # => 6
28
+ */
13
29
  static VALUE max(VALUE class, VALUE encoding_or_name) {
14
30
  return INT2NUM(find_encoding(encoding_or_name)->max_enc_len);
15
31
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CharSize
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/char_size.rb CHANGED
@@ -3,7 +3,15 @@
3
3
  require "char_size/char_size"
4
4
  require "char_size/version"
5
5
 
6
+ # The +CharSize+ module provides functions that return the character size limits
7
+ # of encodings.
6
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]
7
15
  def self.minmax(encoding_or_name)
8
16
  [min(encoding_or_name), max(encoding_or_name)]
9
17
  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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Haines
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
97
111
  description:
98
112
  email:
99
113
  - andrew@haines.org.nz