Module: Bismas::Filter

Extended by:
Bismas, Filter
Included in:
Filter
Defined in:
lib/bismas/filter.rb

Constant Summary

Constants included from Bismas

CATEGORY_CHAR_SKIP, CHARS, DEFAULT_CATEGORY_LENGTH, DEFAULT_ENCODING, DEFAULT_PADDING_LENGTH, REGEX, VERSION

Instance Method Summary collapse

Methods included from Bismas

amend_encoding, chars, encode, execute, execute_options, filter, input_options, mapping, regex, require_gem, safe_yaml, to_xml

Instance Method Details

#run(klass, options, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bismas/filter.rb', line 35

def run(klass, options, &block)
  execute = execute_options(options, &block)
  mapping = mapping(options[:mapping], &block)

  key_format = options[:key_format]

  reader_options, writer_options = input_options(options), {
    encoding:        encoding = options[:output_encoding],
    key:             options[:output_key],
    sort:            options[:sort],
    padding_length:  options[:padding_length],
    category_length: options[:category_length]
  }

  execute[0][bind1 = binding]

  klass.open(options[:output], writer_options) { |writer|
    Reader.parse_file(options[:input], reader_options) { |id, record|
      execute[1][bind2 = binding]
      record = mapping.apply(encode(record, encoding))

      execute[2][bind2]
      writer[key_format % id] = record
    }
  }

  execute[3][bind1]
end