fixed-layout-mapper 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +112 -0
- data/lib/fixed-layout-mapper/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
Sample
|
2
|
+
====
|
1
3
|
require 'pp'
|
2
4
|
require 'fixed-layout-mapper'
|
3
5
|
|
@@ -24,3 +26,113 @@
|
|
24
26
|
# f3=["00", "11", "22"],
|
25
27
|
# f4=["a", "bb", #<struct sub_f1="c", sub_f2="dd">],
|
26
28
|
# f5="123123">
|
29
|
+
|
30
|
+
Detail
|
31
|
+
====
|
32
|
+
|
33
|
+
Define columns
|
34
|
+
----
|
35
|
+
Layout definition is started in "define_layout" method.
|
36
|
+
|
37
|
+
mapper = FixedLayoutMapper::Mapper.define_layout do
|
38
|
+
definitions...
|
39
|
+
end
|
40
|
+
|
41
|
+
Columns are defined by "col" method.
|
42
|
+
|
43
|
+
col symbol, record_def
|
44
|
+
|
45
|
+
record_def is
|
46
|
+
* numeric: define column which cut the string with its width.
|
47
|
+
|
48
|
+
#ex)
|
49
|
+
mapper = FixedLayoutMapper::Mapper.define_layout do
|
50
|
+
col :f, 3
|
51
|
+
end
|
52
|
+
|
53
|
+
p mapper.map("0123")
|
54
|
+
#=> #<struct f="012">
|
55
|
+
|
56
|
+
* array: define array column with use its each contents.
|
57
|
+
|
58
|
+
#ex)
|
59
|
+
mapper = FixedLayoutMapper::Mapper.define_layout do
|
60
|
+
col :f1, [1, 2]
|
61
|
+
col :f2, [1] * 3
|
62
|
+
end
|
63
|
+
|
64
|
+
p mapper.map("001123")
|
65
|
+
#=> #<struct f1=["0", "01"], f2=["1", "2", "3"]>
|
66
|
+
|
67
|
+
* sub_layout_key: define column which use its layout.
|
68
|
+
see Sub layout.
|
69
|
+
|
70
|
+
Sub layout
|
71
|
+
----
|
72
|
+
|
73
|
+
if you want to name to layout, you can use "layout" method.
|
74
|
+
A field defined by "col" method called outside the block of "layout" method is implicitly defined in the default layout.
|
75
|
+
|
76
|
+
layout layout_name(symbol) do
|
77
|
+
column definitions...
|
78
|
+
end
|
79
|
+
|
80
|
+
When sub layout is defined, you can use its layout in other layout definition.
|
81
|
+
|
82
|
+
mapper = FixedLayoutMapper::Mapper.define_layout do
|
83
|
+
layout :sub1 do
|
84
|
+
col :sub_f1, 1
|
85
|
+
col :sub_f2, 2
|
86
|
+
end
|
87
|
+
col :f1, 1
|
88
|
+
col :f2, :sub1
|
89
|
+
end
|
90
|
+
|
91
|
+
p mapper.map("0123")
|
92
|
+
#=> #<struct f1="0", f2=#<struct sub_f1="1", sub_f2="23">>
|
93
|
+
|
94
|
+
You can also use sub layout in array def.
|
95
|
+
|
96
|
+
mapper = FixedLayoutMapper::Mapper.define_layout do
|
97
|
+
layout :sub1 do
|
98
|
+
col :sub_f1, 1
|
99
|
+
col :sub_f2, 2
|
100
|
+
end
|
101
|
+
col :f1, [1, :sub1]
|
102
|
+
end
|
103
|
+
|
104
|
+
p mapper.map("0123")
|
105
|
+
#=> #<struct f1=["0", #<struct sub_f1="1", sub_f2="23"]>
|
106
|
+
|
107
|
+
you can use sub layout in map method.
|
108
|
+
if symbol is passed to the second argument in map method, use its layout.
|
109
|
+
|
110
|
+
mapper = FixedLayoutMapper::Mapper.define_layout do
|
111
|
+
layout :sub1 do
|
112
|
+
col :sub_f1, 1
|
113
|
+
col :sub_f2, 2
|
114
|
+
end
|
115
|
+
col :f1, [1, :sub1]
|
116
|
+
end
|
117
|
+
|
118
|
+
p mapper.map("0123")
|
119
|
+
#=> #<struct f1=["0", #<struct sub_f1="1", sub_f2="23"]>
|
120
|
+
p mapper.map("0123", :sub1)
|
121
|
+
#=> #<struct sub_f1="0", sub_f2="12">
|
122
|
+
|
123
|
+
|
124
|
+
Conversion
|
125
|
+
----
|
126
|
+
|
127
|
+
If "col" method is given block, the raw value is passed to the block and
|
128
|
+
the field value becomes the return value of the block.
|
129
|
+
|
130
|
+
mapper = FixedLayoutMapper::Mapper.define_layout do
|
131
|
+
col :f1, 3 do |v|
|
132
|
+
v + "_" + v
|
133
|
+
end
|
134
|
+
col :f2, 3, &:upcase
|
135
|
+
end
|
136
|
+
|
137
|
+
p mapper.map("012abc")
|
138
|
+
#=> #<struct f1="012_012", f2="ABC">
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixed-layout-mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ''
|
15
15
|
email:
|