structuredtext 1.0.1 → 1.1.0
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/README +6 -2
- data/lib/structuredtext.rb +5 -2
- data/test/test_structuredtext.rb +11 -1
- metadata +2 -2
data/README
CHANGED
@@ -41,8 +41,11 @@ example, the following text:
|
|
41
41
|
|
42
42
|
is parsed into these arrays:
|
43
43
|
|
44
|
-
['apples', '
|
45
|
-
['bananas', '
|
44
|
+
['apples', 'red', 'round']
|
45
|
+
['bananas', 'yellow', 'oblong']
|
46
|
+
|
47
|
+
By default leading and trailing whitespace is removed from each field, though
|
48
|
+
this option may be overridden.
|
46
49
|
|
47
50
|
The field text may contain quoted strings. Delimiter characters inside
|
48
51
|
quotes are not treated as field delimiters. So:
|
@@ -79,6 +82,7 @@ is parsed into these arrays:
|
|
79
82
|
|
80
83
|
1.0.0:: Comment handling and field-delimited text
|
81
84
|
1.0.1:: Source code refinement; no functionality change
|
85
|
+
1.1.0:: Strip whitespace from field edges
|
82
86
|
|
83
87
|
= Copyright
|
84
88
|
|
data/lib/structuredtext.rb
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
# Utilities for working with various kinds of structured text.
|
22
22
|
module StructuredText
|
23
|
-
VERSION = "1.0
|
23
|
+
VERSION = "1.1.0"
|
24
24
|
|
25
25
|
|
26
26
|
# Removes comments from text.
|
@@ -115,7 +115,8 @@ module StructuredText
|
|
115
115
|
# [_lquote_] the left-hand field quote character
|
116
116
|
# [_rquote_] the right-hand field quote character; if unspecified, it is
|
117
117
|
# identical to the left-hand field quote
|
118
|
-
|
118
|
+
# [_strip_] strip whitespace from edges of fields?
|
119
|
+
def initialize(source, delimiter = ",", lquote = '"', rquote = nil, strip = true)
|
119
120
|
@source = source
|
120
121
|
# Escape the custom characters in case the caller provides a regular
|
121
122
|
# expression control character.
|
@@ -136,6 +137,7 @@ module StructuredText
|
|
136
137
|
)
|
137
138
|
EOTEXT
|
138
139
|
@field_regex = Regexp.compile(s, Regexp::EXTENDED)
|
140
|
+
@strip = strip
|
139
141
|
end
|
140
142
|
|
141
143
|
# Enumerate the lines in the source yielding arrays of comma-separated
|
@@ -157,6 +159,7 @@ EOTEXT
|
|
157
159
|
field += text if not text.nil?
|
158
160
|
else
|
159
161
|
# Add field to the record at a delimiter.
|
162
|
+
field.strip! if @strip
|
160
163
|
record << field
|
161
164
|
field = ""
|
162
165
|
end
|
data/test/test_structuredtext.rb
CHANGED
@@ -60,6 +60,11 @@ class DelimitedReaderTestCase < Test::Unit::TestCase
|
|
60
60
|
assert_equal([["a", "b", "c"], ["d", "e", "f"]], StructuredText::DelimitedReader.new("a,b,c\nd,e,f").collect)
|
61
61
|
# Multiline: variying record length
|
62
62
|
assert_equal([["a", "b", "c"], ["d", "e"]], StructuredText::DelimitedReader.new("a,b,c\nd,e").collect)
|
63
|
+
# Strip
|
64
|
+
assert_equal([["a", "b", "c"]], StructuredText::DelimitedReader.new(" a , b , c ").collect)
|
65
|
+
# No-strip
|
66
|
+
assert_equal([[" a ", " b ", " c "]],
|
67
|
+
StructuredText::DelimitedReader.new(" a , b , c ", ",", '"', '"', false).collect)
|
63
68
|
end
|
64
69
|
|
65
70
|
def test_quoted
|
@@ -120,6 +125,11 @@ class LabeledReaderTestCase < Test::Unit::TestCase
|
|
120
125
|
# Multiline
|
121
126
|
assert_equal([{"X"=>"a", "Y"=>"b", "Z"=>"c"}, {"X"=>"d", "Y"=>"e", "Z"=>"f"}],
|
122
127
|
StructuredText::LabeledDelimitedReader.new("X,Y,Z\na,b,c\nd,e,f").collect)
|
128
|
+
# Strip
|
129
|
+
assert_equal([{"X"=>"a", "Y"=>"b", "Z"=>"c"}], StructuredText::LabeledDelimitedReader.new(" X , Y , Z \n a , b , c ").collect)
|
130
|
+
# No-strip
|
131
|
+
assert_equal([{" X "=>" a ", " Y "=>" b ", " Z "=>" c "}],
|
132
|
+
StructuredText::LabeledDelimitedReader.new(" X , Y , Z \n a , b , c ", ",", '"', '"', false).collect)
|
123
133
|
end
|
124
134
|
|
125
135
|
def test_exception
|
@@ -138,7 +148,7 @@ bananas|yellow|oblong
|
|
138
148
|
; The end
|
139
149
|
EOTEXT
|
140
150
|
r = StructuredText::LabeledDelimitedReader.new(StructuredText::CommentedReader.new(text, ";"), "|", "(", ")")
|
141
|
-
assert_equal([{'Shape'=>'round
|
151
|
+
assert_equal([{'Shape'=>'round', 'Fruit'=>'apples', 'Color'=>'(red|green)'},
|
142
152
|
{'Shape'=>'oblong', 'Fruit'=>'bananas', 'Color'=>'yellow'}], r.collect)
|
143
153
|
end
|
144
154
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: structuredtext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- W.P. McNeill
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-20 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|