Skip to content

Commit c26875b

Browse files
committed
Update gemspec
1 parent 6ca4f93 commit c26875b

File tree

4 files changed

+108
-18
lines changed

4 files changed

+108
-18
lines changed

CODE_OF_CONDUCT.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Contributor Code of Conduct
2+
3+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4+
5+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6+
7+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8+
9+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10+
11+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12+
13+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)

LICENSE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
The MIT License (MIT)
2+
====================
3+
4+
* Copyright © 2013 David Chelimsky, Myron Marston, Jon Rowe, Sam Phippen, Xavier Shay, Bradley Schaefer
5+
6+
Permission is hereby granted, free of charge, to any person obtaining
7+
a copy of this software and associated documentation files (the
8+
"Software"), to deal in the Software without restriction, including
9+
without limitation the rights to use, copy, modify, merge, publish,
10+
distribute, sublicense, and/or sell copies of the Software, and to
11+
permit persons to whom the Software is furnished to do so, subject to
12+
the following conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# EncodedString
22

3-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/encoded_string`. To experiment with that code, run `bin/console` for an interactive prompt.
4-
5-
TODO: Delete this and the text above, and describe your gem
3+
EncodedString is a wrapper for a string and a given encoding that handles operations on
4+
strings with different encodings, invalid encodings, have no known conversion method,
5+
or are otherwise incompatible, all without raising excpetions
66

77
## Installation
88

@@ -22,7 +22,65 @@ Or install it yourself as:
2222

2323
## Usage
2424

25-
TODO: Write usage instructions here
25+
```ruby
26+
EncodedString.pick_encoding(str1, str2)
27+
28+
def build_encoded_string(string, target_encoding = string.encoding)
29+
EncodedString.new(string, target_encoding)
30+
end
31+
str = "abc".encode('ASCII-8BIT')
32+
str = EncodedString.new(str, target_encoding = string.encoding)
33+
expect(str.source_encoding.to_s).to eq('ASCII-8BIT')
34+
str.split("\n")
35+
str << "123"
36+
str.to_s
37+
```
38+
39+
## About
40+
41+
Encoding Exceptions:
42+
43+
```plain
44+
Raised by Encoding and String methods:
45+
Encoding::UndefinedConversionError:
46+
when a transcoding operation fails
47+
if the String contains characters invalid for the target encoding
48+
e.g. "\x80".encode('UTF-8','ASCII-8BIT')
49+
vs "\x80".encode('UTF-8','ASCII-8BIT', undef: :replace, replace: '<undef>')
50+
# => '<undef>'
51+
Encoding::CompatibilityError
52+
when Encoding.compatibile?(str1, str2) is nil
53+
e.g. utf_16le_emoji_string.split("\n")
54+
e.g. valid_unicode_string.encode(utf8_encoding) << ascii_string
55+
Encoding::InvalidByteSequenceError:
56+
when the string being transcoded contains a byte invalid for
57+
either the source or target encoding
58+
e.g. "\x80".encode('UTF-8','US-ASCII')
59+
vs "\x80".encode('UTF-8','US-ASCII', invalid: :replace, replace: '<byte>')
60+
# => '<byte>'
61+
ArgumentError
62+
when operating on a string with invalid bytes
63+
e.g."\x80".split("\n")
64+
TypeError
65+
when a symbol is passed as an encoding
66+
Encoding.find(:"UTF-8")
67+
when calling force_encoding on an object
68+
that doesn't respond to #to_str
69+
70+
Raised by transcoding methods:
71+
Encoding::ConverterNotFoundError:
72+
when a named encoding does not correspond with a known converter
73+
e.g. 'abc'.force_encoding('UTF-8').encode('foo')
74+
or a converter path cannot be found
75+
e.g. "\x80".force_encoding('ASCII-8BIT').encode('Emacs-Mule')
76+
77+
Raised by byte <-> char conversions
78+
RangeError: out of char range
79+
e.g. the UTF-16LE emoji: 128169.chr
80+
```
81+
82+
See [lib/encoded_string.rb](lib/encoded_string.rb) and
83+
[spec/encoded_string_spec.rb](spec/encoded_string_spec.rb) for more information.
2684

2785
## Development
2886

@@ -32,5 +90,10 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
3290

3391
## Contributing
3492

35-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/encoded_string.
93+
Bug reports and pull requests are welcome on GitHub at https://github.com/bf4/encoded_string. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
94+
95+
96+
## License
97+
98+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
3699

encoded_string.gemspec

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,13 @@ Gem::Specification.new do |spec|
77
spec.name = "encoded_string"
88
spec.version = EncodedString::VERSION
99
spec.authors = ["Benjamin Fleischer"]
10-
spec.email = ["TODO: Write your email address"]
10+
spec.email = ["[email protected]"]
1111

12-
spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.}
13-
spec.description = %q{TODO: Write a longer description or delete this line.}
14-
spec.homepage = "TODO: Put your gem's website or public repo URL here."
15-
16-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17-
# delete this section to allow pushing this gem to any host.
18-
if spec.respond_to?(:metadata)
19-
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20-
else
21-
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22-
end
12+
spec.summary = %q{Handle string operations without worrying about raising encoding exceptions.}
13+
spec.description = %q{Extracted from rspec-support. See https://github.com/rspec/rspec-support/issues/249.}
14+
spec.homepage = "https://github.com/bf4/encoded_string"
2315

2416
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25-
spec.bindir = "exe"
2617
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2718
spec.require_paths = ["lib"]
2819

0 commit comments

Comments
 (0)