sugar-high 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sugar-high/string.rb +33 -0
- data/spec/sugar-high/string_spec.rb +46 -0
- data/sugar-high.gemspec +6 -3
- metadata +6 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class String
|
2
|
+
def insert_before_last str, marker = 'end'
|
3
|
+
res = []
|
4
|
+
found = false
|
5
|
+
marker = case marker
|
6
|
+
when Symbol, String
|
7
|
+
marker.to_s
|
8
|
+
when Hash
|
9
|
+
marker[:marker].to_s
|
10
|
+
else
|
11
|
+
raise ArgumentException, "last argument is the marker and must be a String, Symbol or even Hash with a :marker option pointing to the marker (String or Symbol)"
|
12
|
+
end
|
13
|
+
|
14
|
+
marker = Regexp.escape(marker.reverse)
|
15
|
+
nl = Regexp.escape("\n")
|
16
|
+
# puts self
|
17
|
+
# puts "marker: #{marker}"
|
18
|
+
# puts "nl: #{nl}"
|
19
|
+
# puts "str: #{str}"
|
20
|
+
|
21
|
+
self.reverse.each_line do |x|
|
22
|
+
x.gsub! /#{nl}/, ''
|
23
|
+
if !found && x =~ /#{marker}/
|
24
|
+
replace = "#{str}\n" << x.reverse
|
25
|
+
res << replace
|
26
|
+
found = true
|
27
|
+
else
|
28
|
+
res << x.reverse
|
29
|
+
end
|
30
|
+
end
|
31
|
+
res = res.reverse.join("\n")
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sugar-high/string'
|
3
|
+
|
4
|
+
describe "SugarHigh" do
|
5
|
+
describe 'String pack' do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@s = %q{
|
9
|
+
class Abc
|
10
|
+
def begin
|
11
|
+
|
12
|
+
end
|
13
|
+
end}
|
14
|
+
|
15
|
+
@s = %q{
|
16
|
+
class Abc
|
17
|
+
def begin
|
18
|
+
|
19
|
+
end
|
20
|
+
blip}
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
describe '#insert_before_last' do
|
25
|
+
it "should insert '# hello' before last end (default)" do
|
26
|
+
@s.insert_before_last(' # hello').should match /# hello\s*end/
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should insert '# hello' before last 'blip' (explicit String marker)" do
|
30
|
+
@s.insert_before_last(' # hello', 'blip').should match /# hello\s*blip/
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should insert '# hello' before last 'blip' (explicit Symbol marker)" do
|
34
|
+
@s.insert_before_last(' # hello', :blip).should match /# hello\s*blip/
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should insert '# hello' before last 'blip' (explicit Hash-String marker)" do
|
38
|
+
@s.insert_before_last(' # hello', :marker => 'blip').should match /# hello\s*blip/
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should insert '# hello' before last 'blip' (explicit Hash-Symbol marker)" do
|
42
|
+
@s.insert_before_last(' # hello', :marker => :blip).should match /# hello\s*blip/
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/sugar-high.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sugar-high}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-07}
|
13
13
|
s.description = %q{More Ruby sugar - inspired by the 'zuker' project}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
"lib/sugar-high/regexp.rb",
|
41
41
|
"lib/sugar-high/rspec/configure.rb",
|
42
42
|
"lib/sugar-high/rspec/matchers/have_aliases.rb",
|
43
|
+
"lib/sugar-high/string.rb",
|
43
44
|
"spec/fixtures/empty.txt",
|
44
45
|
"spec/fixtures/non-empty.txt",
|
45
46
|
"spec/spec_helper.rb",
|
@@ -56,6 +57,7 @@ Gem::Specification.new do |s|
|
|
56
57
|
"spec/sugar-high/module_spec.rb",
|
57
58
|
"spec/sugar-high/path_spec.rb",
|
58
59
|
"spec/sugar-high/regexp_spec.rb",
|
60
|
+
"spec/sugar-high/string_spec.rb",
|
59
61
|
"sugar-high.gemspec"
|
60
62
|
]
|
61
63
|
s.homepage = %q{http://github.com/kristianmandrup/sugar-high}
|
@@ -76,7 +78,8 @@ Gem::Specification.new do |s|
|
|
76
78
|
"spec/sugar-high/methods_spec.rb",
|
77
79
|
"spec/sugar-high/module_spec.rb",
|
78
80
|
"spec/sugar-high/path_spec.rb",
|
79
|
-
"spec/sugar-high/regexp_spec.rb"
|
81
|
+
"spec/sugar-high/regexp_spec.rb",
|
82
|
+
"spec/sugar-high/string_spec.rb"
|
80
83
|
]
|
81
84
|
|
82
85
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-07 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- lib/sugar-high/regexp.rb
|
96
96
|
- lib/sugar-high/rspec/configure.rb
|
97
97
|
- lib/sugar-high/rspec/matchers/have_aliases.rb
|
98
|
+
- lib/sugar-high/string.rb
|
98
99
|
- spec/fixtures/empty.txt
|
99
100
|
- spec/fixtures/non-empty.txt
|
100
101
|
- spec/spec_helper.rb
|
@@ -111,6 +112,7 @@ files:
|
|
111
112
|
- spec/sugar-high/module_spec.rb
|
112
113
|
- spec/sugar-high/path_spec.rb
|
113
114
|
- spec/sugar-high/regexp_spec.rb
|
115
|
+
- spec/sugar-high/string_spec.rb
|
114
116
|
- sugar-high.gemspec
|
115
117
|
has_rdoc: true
|
116
118
|
homepage: http://github.com/kristianmandrup/sugar-high
|
@@ -159,3 +161,4 @@ test_files:
|
|
159
161
|
- spec/sugar-high/module_spec.rb
|
160
162
|
- spec/sugar-high/path_spec.rb
|
161
163
|
- spec/sugar-high/regexp_spec.rb
|
164
|
+
- spec/sugar-high/string_spec.rb
|