feed_yamlizer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/feed_yamlizer/version.rb +1 -1
- data/lib/string_ext.rb +44 -0
- metadata +3 -2
data/lib/string_ext.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
def wrap(width, hanging_indent = 0, magic_lists = false)
|
4
|
+
lines = self.split(/\n/)
|
5
|
+
|
6
|
+
lines.collect! do |line|
|
7
|
+
|
8
|
+
if magic_lists
|
9
|
+
line =~ /^([\s\-\d\.\:]*\s)/
|
10
|
+
else
|
11
|
+
line =~ /^([\s]*\s)/
|
12
|
+
end
|
13
|
+
|
14
|
+
indent = $1.length + hanging_indent rescue hanging_indent
|
15
|
+
|
16
|
+
buffer = ""
|
17
|
+
first = true
|
18
|
+
|
19
|
+
while line.length > 0
|
20
|
+
first ? (i, first = 0, false) : i = indent
|
21
|
+
pos = width - i
|
22
|
+
|
23
|
+
if line.length > pos and line[0..pos] =~ /^(.+)\s/
|
24
|
+
subline = $1
|
25
|
+
else
|
26
|
+
subline = line[0..pos]
|
27
|
+
end
|
28
|
+
buffer += " " * i + subline + "\n"
|
29
|
+
line.tail!(subline.length)
|
30
|
+
end
|
31
|
+
buffer[0..-2]
|
32
|
+
end
|
33
|
+
|
34
|
+
lines.join("\n")
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def tail!(pos)
|
39
|
+
self[0..pos] = ""
|
40
|
+
strip!
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Choi
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/feed_yamlizer/html_cleaner.rb
|
66
66
|
- lib/feed_yamlizer/html_listener.rb
|
67
67
|
- lib/feed_yamlizer/version.rb
|
68
|
+
- lib/string_ext.rb
|
68
69
|
has_rdoc: true
|
69
70
|
homepage: https://github.com/danchoi/feed_yamlizer
|
70
71
|
licenses: []
|