Class: FixedLayoutMapper::Mapper
- Inherits:
-
Object
- Object
- FixedLayoutMapper::Mapper
show all
- Defined in:
- lib/fixed-layout-mapper.rb
Defined Under Namespace
Classes: ArrayMapper, ColumnMapper, Layout, SimpleMapper, SubLayoutMapper
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {:encoding => Encoding.default_external}) ⇒ Mapper
Returns a new instance of Mapper.
134
135
136
137
138
139
140
141
|
# File 'lib/fixed-layout-mapper.rb', line 134
def initialize(opts = {:encoding => Encoding.default_external})
@current_layout = :default_layout
@current_length_condition = LENGTH_CONDITION_ALLOW_LONG
@layouts = {}
@result_class = {}
@length_conditions = {}
@encoding = opts[:encoding]
end
|
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
133
134
135
|
# File 'lib/fixed-layout-mapper.rb', line 133
def encoding
@encoding
end
|
#length_condition ⇒ Object
Returns the value of attribute length_condition.
133
134
135
|
# File 'lib/fixed-layout-mapper.rb', line 133
def length_condition
@length_condition
end
|
Class Method Details
.define_layout(opts = {:encoding => Encoding.default_external}, &block) ⇒ Object
126
127
128
129
130
|
# File 'lib/fixed-layout-mapper.rb', line 126
def define_layout(opts = {:encoding => Encoding.default_external}, &block)
obj = Mapper.new(opts)
obj.define_layout(&block)
obj
end
|
Instance Method Details
#define_layout(&block) ⇒ Object
143
144
145
146
|
# File 'lib/fixed-layout-mapper.rb', line 143
def define_layout(&block)
instance_eval(&block)
build_layout
end
|
#get_layout(layout_id = @current_layout) ⇒ Object
153
154
155
|
# File 'lib/fixed-layout-mapper.rb', line 153
def get_layout(layout_id = @current_layout)
@layouts[layout_id]
end
|
#get_result_class(layout_id) ⇒ Object
157
158
159
|
# File 'lib/fixed-layout-mapper.rb', line 157
def get_result_class(layout_id)
@result_class[layout_id]
end
|
#length_condigion(value) ⇒ Object
161
162
163
|
# File 'lib/fixed-layout-mapper.rb', line 161
def length_condigion(value)
@length_condition = value
end
|
#map(data, layout_id = @current_layout) ⇒ Object
148
149
150
151
|
# File 'lib/fixed-layout-mapper.rb', line 148
def map(data, layout_id = @current_layout)
obj, = @layouts[layout_id].map(data.unpack("C*"), @result_class[layout_id])
obj
end
|