Class: SelectMap
Overview
Map selects according to a RE
Instance Attribute Summary
Attributes inherited from Stage
#errors, #in_fields, #in_sep, #out_fields, #out_sep
Instance Method Summary collapse
- #declare ⇒ Object
-
#initialize(*args) ⇒ SelectMap
constructor
A new instance of SelectMap.
- #process(input, output) ⇒ Object
Methods inherited from MapBase
#process_begin, #process_end, #run
Methods inherited from Stage
#catch_errors, #copy_struct, #emit, #emit_separator, #field, #field_separator, #new_input, #new_output, #prepare, #process_step, #write_out
Constructor Details
#initialize(*args) ⇒ SelectMap
Returns a new instance of SelectMap.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/mrtoolkit.rb', line 266 def initialize(*args) raise ArgumentError if args.size < 1 @re = args[0] if args[1] @field = args[1] else @field = 0 end if args[2] @n = args[2].to_i - 1 else @n = 0 end end |
Instance Method Details
#declare ⇒ Object
280 281 282 283 284 |
# File 'lib/mrtoolkit.rb', line 280 def declare (0..@n).each {|i| field "col#{i}"} (0..@n).each {|i| emit "col#{i}"} end |
#process(input, output) ⇒ Object
286 287 288 289 290 291 |
# File 'lib/mrtoolkit.rb', line 286 def process(input, output) if input[@field] =~ @re return copy_struct(input, output) end nil end |