stringincrement 0.0.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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/stringincrement.rb +27 -0
- data/lib/stringincrement/version.rb +3 -0
- data/spec/stringincrement_spec.rb +20 -0
- data/stringincrement.gemspec +24 -0
- metadata +87 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "stringincrement/version"
|
2
|
+
|
3
|
+
module Stringincrement
|
4
|
+
def increment
|
5
|
+
remains, last_number = self.match( /(.*?)(\d*)$/ ).captures
|
6
|
+
if last_number != ""
|
7
|
+
return "#{remains}#{last_number.to_i + 1}"
|
8
|
+
else
|
9
|
+
remains = remains.split("").reverse
|
10
|
+
overbit = 1
|
11
|
+
remains.map! do |char|
|
12
|
+
ret = char[0] + overbit
|
13
|
+
if ret == 123 || ret == 91
|
14
|
+
ret -= 26
|
15
|
+
else
|
16
|
+
overbit = 0
|
17
|
+
end
|
18
|
+
ret.chr
|
19
|
+
end
|
20
|
+
return remains.reverse.join("")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class String
|
26
|
+
include Stringincrement
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'stringincrement'
|
2
|
+
|
3
|
+
describe Stringincrement do
|
4
|
+
it "should install itself into String" do
|
5
|
+
"random string".respond_to?(:increment).should be_true
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should increase the last number" do
|
9
|
+
"1".increment.should == "2"
|
10
|
+
"9".increment.should == "10"
|
11
|
+
"aa1".increment.should == "aa2"
|
12
|
+
"aa9".increment.should == "aa10"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should increase strings (if no number is found)" do
|
16
|
+
"a".increment.should == "b"
|
17
|
+
"az".increment.should == "ba"
|
18
|
+
"azzz".increment.should == "baaa"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "stringincrement/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "stringincrement"
|
7
|
+
s.version = Stringincrement::VERSION
|
8
|
+
s.authors = ["Jan"]
|
9
|
+
s.email = ["jan@kopfmaschine.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{smartly increases a stringvalue}
|
12
|
+
s.description = %q{a => b, azzz => baaa, aa11 => aa12, ab99 => ab100}
|
13
|
+
|
14
|
+
s.rubyforge_project = "stringincrement"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stringincrement
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jan
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-12-16 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: a => b, azzz => baaa, aa11 => aa12, ab99 => ab100
|
36
|
+
email:
|
37
|
+
- jan@kopfmaschine.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- Rakefile
|
48
|
+
- lib/stringincrement.rb
|
49
|
+
- lib/stringincrement/version.rb
|
50
|
+
- spec/stringincrement_spec.rb
|
51
|
+
- stringincrement.gemspec
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: ""
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project: stringincrement
|
82
|
+
rubygems_version: 1.6.2
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: smartly increases a stringvalue
|
86
|
+
test_files: []
|
87
|
+
|