rsplit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +57 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rsplit.rb +39 -0
- data/lib/rsplit/version.rb +3 -0
- data/rsplit.gemspec +27 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 95101f15c0ddc30d20c39200daaf556c44dd12c3
|
4
|
+
data.tar.gz: 66a90f5715bc6b986f4300b084179ae17e8baa55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: def6bca623cc837da97513a4f1b136ba73015efbb2f753c8ed1863f52055c3885619f248271932e99ea394259498bfe98ce5ef4a8815e14367614a90941878b1
|
7
|
+
data.tar.gz: d369b94b17d8ea785e635bf63059efc5ba1a318566f157550ba6e0037096dcec17e1b1e577186af63437005d2596c62b2b8d7d780e7667247c42a74fa7621d94
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The zlib license (Zlib)
|
2
|
+
|
3
|
+
Copyright (c) 2015 OTSUKA Tatsuya
|
4
|
+
|
5
|
+
This software is provided 'as-is', without any express or implied
|
6
|
+
warranty. In no event will the authors be held liable for any damages
|
7
|
+
arising from the use of this software.
|
8
|
+
|
9
|
+
Permission is granted to anyone to use this software for any purpose,
|
10
|
+
including commercial applications, and to alter it and redistribute it
|
11
|
+
freely, subject to the following restrictions:
|
12
|
+
|
13
|
+
1. The origin of this software must not be misrepresented; you must not
|
14
|
+
claim that you wrote the original software. If you use this software
|
15
|
+
in a product, an acknowledgment in the product documentation would be
|
16
|
+
appreciated but is not required.
|
17
|
+
|
18
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
19
|
+
misrepresented as being the original software.
|
20
|
+
|
21
|
+
3. This notice may not be removed or altered from any source
|
22
|
+
distribution.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# rsplit
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rsplit.svg)](http://badge.fury.io/rb/rsplit)
|
4
|
+
[![Build Status](https://travis-ci.org/Tatzyr/rsplit.svg?branch=master)](https://travis-ci.org/Tatzyr/rsplit)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/Tatzyr/rsplit/badges/gpa.svg)](https://codeclimate.com/github/Tatzyr/rsplit)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/Tatzyr/rsplit/badges/coverage.svg)](https://codeclimate.com/github/Tatzyr/rsplit/coverage)
|
7
|
+
[![Dependency Status](https://gemnasium.com/Tatzyr/rsplit.svg)](https://gemnasium.com/Tatzyr/rsplit)
|
8
|
+
|
9
|
+
Divides string into substrings based on a delimiter (starting from right),
|
10
|
+
returning an array of these substrings.
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
"1.2.3".split(".", 2) #=> ["1", "2.3"]
|
14
|
+
"1.2.3".rsplit(".", 2) #=> ["1.2", "3"]
|
15
|
+
```
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'rsplit'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install rsplit
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require "rsplit"
|
37
|
+
|
38
|
+
" now's the time".rsplit #=> ["now's", "the", "time"]
|
39
|
+
" now's the time".rsplit(" ") #=> ["now's", "the", "time"]
|
40
|
+
|
41
|
+
"mellow yellow".rsplit("ello") #=> ["m", "w y", "w"]
|
42
|
+
"..1.2..3.4".rsplit(".") #=> ["1", "2", "", "3", "4"]
|
43
|
+
"..1.2..3.4".rsplit(".", 4) #=> ["..1.2", "", "3", "4"]
|
44
|
+
"..1.2..3.4".rsplit(".", -1) #=> ["", "", "1", "2", "", "3", "4"]
|
45
|
+
|
46
|
+
"".rsplit(".") #=> []
|
47
|
+
```
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
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).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Tatzyr/rsplit.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rsplit"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/rsplit.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "rsplit/version"
|
2
|
+
|
3
|
+
module RSplit
|
4
|
+
def rsplit(str, sep = nil, limit = 0)
|
5
|
+
valid_encoding?(str)
|
6
|
+
sep = $; if sep.nil?
|
7
|
+
case sep
|
8
|
+
when NilClass
|
9
|
+
# do nothing
|
10
|
+
when String
|
11
|
+
valid_encoding?(sep)
|
12
|
+
sep = sep.reverse
|
13
|
+
else
|
14
|
+
raise TypeError, "wrong argument type #{sep.class} (expected String)"
|
15
|
+
end
|
16
|
+
|
17
|
+
str.reverse.split(sep, limit).map(&:reverse).reverse
|
18
|
+
end
|
19
|
+
|
20
|
+
module_function :rsplit
|
21
|
+
|
22
|
+
# Avoid Bug #11387
|
23
|
+
# https://bugs.ruby-lang.org/issues/11387
|
24
|
+
def self.valid_encoding?(string)
|
25
|
+
raise ArgumentError, "invalid byte sequence in #{string.encoding.name}" unless string.valid_encoding?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
class String
|
31
|
+
# :call-seq:
|
32
|
+
# rsplit(sep = $;, limit = 0)
|
33
|
+
#
|
34
|
+
# Divides string into substrings based on a delimiter (starting from right), returning an array of these substrings.
|
35
|
+
#
|
36
|
+
def rsplit(*args)
|
37
|
+
RSplit.rsplit(self, *args)
|
38
|
+
end
|
39
|
+
end
|
data/rsplit.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rsplit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rsplit"
|
8
|
+
spec.version = RSplit::VERSION
|
9
|
+
spec.authors = ["OTSUKA Tatsuya"]
|
10
|
+
spec.email = ["tatzyr@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Divides string into substrings based on a delimiter (starting from right), returning an array of these substrings.}
|
13
|
+
spec.homepage = "https://github.com/tatzyr/rsplit"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.required_ruby_version = ">= 2.0.0"
|
21
|
+
spec.license = "Zlib"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsplit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- OTSUKA Tatsuya
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- tatzyr@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/rsplit.rb
|
86
|
+
- lib/rsplit/version.rb
|
87
|
+
- rsplit.gemspec
|
88
|
+
homepage: https://github.com/tatzyr/rsplit
|
89
|
+
licenses:
|
90
|
+
- Zlib
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 2.0.0
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.4.8
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Divides string into substrings based on a delimiter (starting from right),
|
112
|
+
returning an array of these substrings.
|
113
|
+
test_files: []
|