arb-str 1.0.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/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/arb-str.gemspec +26 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/arb/str.rb +63 -0
- data/lib/arb/str/version.rb +5 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab76b341c5f0d3b70865492fb08c40cc0c0f7ef0
|
4
|
+
data.tar.gz: 38411eea6298ebff3106cdefa88581f7f40b8d38
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b153b99c8a065d1d96cbad13345b9dbda3967d085d2f135ed52be4970c23c2a310d37bd1239058782eb9090621d0b187eb61c8b2802a4f8ad575bfc87d2c53f5
|
7
|
+
data.tar.gz: 80303af2c6d2195ec12ab0cf31f59168254fd9fdce14bf65ea5efc3a9cec55e806cbf1460b05e9fbf4427c61a9a047a752ed85758cee45086f54b8c96864ded7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Arb::Str
|
2
|
+
|
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/arb/str`. 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
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'arb-str'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install arb-str
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/arb-str.
|
36
|
+
|
data/Rakefile
ADDED
data/arb-str.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'arb/str/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "arb-str"
|
8
|
+
spec.version = Arb::Str::VERSION
|
9
|
+
spec.authors = ["AryBin"]
|
10
|
+
spec.email = ["arybin@163.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Enhance of String.}
|
13
|
+
spec.description = %q{Enhance of String.}
|
14
|
+
spec.homepage = "https://github.com/arybin-cn/arb-str"
|
15
|
+
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "arb/str"
|
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/arb/str.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "arb/str/version"
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
# Examples:
|
6
|
+
#
|
7
|
+
# String#enum:
|
8
|
+
# 'http://?/?/?'.enum '?',%w{domain1 domain2},%w{pictures videos jokes},1..3
|
9
|
+
#
|
10
|
+
# => ["http://domain1/pictures/1",
|
11
|
+
# "http://domain1/pictures/2",
|
12
|
+
# "http://domain1/pictures/3",
|
13
|
+
# "http://domain1/videos/1",
|
14
|
+
# "http://domain1/videos/2",
|
15
|
+
# "http://domain1/videos/3",
|
16
|
+
# "http://domain1/jokes/1",
|
17
|
+
# "http://domain1/jokes/2",
|
18
|
+
# "http://domain1/jokes/3",
|
19
|
+
# "http://domain2/pictures/1",
|
20
|
+
# "http://domain2/pictures/2",
|
21
|
+
# "http://domain2/pictures/3",
|
22
|
+
# "http://domain2/videos/1",
|
23
|
+
# "http://domain2/videos/2",
|
24
|
+
# "http://domain2/videos/3",
|
25
|
+
# "http://domain2/jokes/1",
|
26
|
+
# "http://domain2/jokes/2",
|
27
|
+
# "http://domain2/jokes/3"]
|
28
|
+
#
|
29
|
+
|
30
|
+
module Arb
|
31
|
+
module Str
|
32
|
+
#Clean room here.
|
33
|
+
Object.new.instance_eval do
|
34
|
+
o=self
|
35
|
+
e=:inner_enum
|
36
|
+
o.singleton_class.send :define_method,e do |str,wildcard,enumerators|
|
37
|
+
index=str.index wildcard
|
38
|
+
return [str] unless index && enumerators.size>0
|
39
|
+
[].tap {|res|
|
40
|
+
enumerator=enumerators.shift
|
41
|
+
#Make sure enumerator is enumerable here.
|
42
|
+
enumerator=[enumerator] unless enumerator.respond_to? :each
|
43
|
+
enumerator.each do |item|
|
44
|
+
str_dup=str.dup
|
45
|
+
str_dup[index..index+wildcard.length-1]=item.to_s
|
46
|
+
res<<o.send(e,str_dup,wildcard,enumerators.dup)
|
47
|
+
end
|
48
|
+
#res.size==0 if the enumerator is empty(eg. [])
|
49
|
+
res<<str if res.size==0
|
50
|
+
}.flatten
|
51
|
+
end
|
52
|
+
#String#enum(wildcard,enumerator0,enumerator1,enumerator2,...)
|
53
|
+
String.send :define_method, :enum do |*enumerators,&blk|
|
54
|
+
return nil if enumerators.size < 1
|
55
|
+
return nil if enumerators[1..-1].map(&:to_s).include?(enumerators.first.to_s)
|
56
|
+
#Wildcard could not be enumerated itself.
|
57
|
+
o.send(e,self,enumerators.first,enumerators[1..-1]).tap do |res|
|
58
|
+
res.each{|str| blk[str]} if blk
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arb-str
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- AryBin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-12 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.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
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
|
+
description: Enhance of String.
|
42
|
+
email:
|
43
|
+
- arybin@163.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- arb-str.gemspec
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/arb/str.rb
|
56
|
+
- lib/arb/str/version.rb
|
57
|
+
homepage: https://github.com/arybin-cn/arb-str
|
58
|
+
licenses: []
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.4.8
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Enhance of String.
|
80
|
+
test_files: []
|