flat_out 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +11 -0
- data/lib/flat_out.rb +21 -9
- data/spec/flat_out_spec.rb +9 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -137,6 +137,7 @@ Command:
|
|
137
137
|
|
138
138
|
Description:
|
139
139
|
This will return the formatted fixed length record which you can write to a file.
|
140
|
+
It will blank fill or truncate the output to the correct length.
|
140
141
|
|
141
142
|
Command:
|
142
143
|
|
@@ -163,6 +164,16 @@ Command:
|
|
163
164
|
FlatOut.phone_squeeze('(800) 555-1212 Ext 234') == "8005551212Ext234"
|
164
165
|
FlatOut.phone_squeeze('(800) GOT-MILK') == "800GOTMILK"
|
165
166
|
|
167
|
+
== Working with Templates
|
168
|
+
|
169
|
+
You can also specify a template during initialization, and then put values in the template
|
170
|
+
with an array.
|
171
|
+
|
172
|
+
example:
|
173
|
+
f = FlatOut.new(18, :template => [[5,1],[5,6],[4.2,11]]) # '123456789012345678'
|
174
|
+
val = ['ABCD',10,10.23]
|
175
|
+
f.put(val) # 'ABCD 000100010.23 '
|
176
|
+
|
166
177
|
== Full Cycle Example:
|
167
178
|
|
168
179
|
myline = FlatOut.new(80)
|
data/lib/flat_out.rb
CHANGED
@@ -8,10 +8,11 @@ class FlatOut
|
|
8
8
|
@flat_length = rec_length
|
9
9
|
@base = options[:base] ||= @base ||= 1
|
10
10
|
@format = options[:format] ||= @format ||= :len_pos_fld
|
11
|
+
@template = options[:template] ||= @template ||= []
|
11
12
|
end
|
12
13
|
|
13
14
|
def to_s
|
14
|
-
@flat_out
|
15
|
+
(@flat_out + (' ' * @flat_length))[0...@flat_length]
|
15
16
|
end
|
16
17
|
|
17
18
|
def self.phone_squeeze(fld)
|
@@ -22,17 +23,28 @@ class FlatOut
|
|
22
23
|
fld.gsub(/[^\d]/,"")
|
23
24
|
end
|
24
25
|
|
25
|
-
def put p1, p2, p3
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
def put p1, p2=1, p3=''
|
27
|
+
if @template.size > 0 && p1.class == Array
|
28
|
+
fld = p1
|
29
|
+
else
|
30
|
+
case @format
|
31
|
+
when :len_pos_fld then (len = p1; pos = p2; fld = p3)
|
32
|
+
when :len_fld_pos then (len = p1; fld = p2; pos = p3)
|
33
|
+
when :pos_len_fld then (pos = p1; len = p2; fld = p3)
|
34
|
+
when :pos_fld_len then (pos = p1; fld = p2; len = p3)
|
35
|
+
when :fld_pos_len then (fld = p1; pos = p2; len = p3)
|
36
|
+
when :fld_len_pos then (fld = p1; len = p2; pos = p3)
|
37
|
+
else (len = p1; pos = p2; fld = p3)
|
38
|
+
end
|
33
39
|
end
|
34
40
|
|
35
41
|
case fld
|
42
|
+
when Array
|
43
|
+
fld.each_with_index do |field,idx|
|
44
|
+
len = @template[idx][0]
|
45
|
+
pos = @template[idx][1]
|
46
|
+
put len, pos, field
|
47
|
+
end
|
36
48
|
when String
|
37
49
|
put_alpha len, pos, fld
|
38
50
|
when Integer
|
data/spec/flat_out_spec.rb
CHANGED
@@ -144,6 +144,15 @@ describe "put float with negative length" do
|
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
|
+
describe "put with a template" do
|
148
|
+
it "should put multiple fields" do
|
149
|
+
f = FlatOut.new(18, :template => [[5,1],[5,6],[4.2,11]])
|
150
|
+
val = ['ABCD',10,10.23]
|
151
|
+
f.put(val)
|
152
|
+
f.to_s.should == 'ABCD 000100010.23 '
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
147
156
|
describe "digits_only" do
|
148
157
|
it "should remove non-digit characters" do
|
149
158
|
FlatOut.digits_only('01(2)-3ABC4-5^678').should == "012345678"
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: flat_out
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Anil Sharma
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-05-
|
13
|
+
date: 2012-05-30 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|