module Midos

Constants

DEFAULT_ENCODING

Default file encoding

DEFAULT_FS

Field separator

DEFAULT_LE

Line ending

DEFAULT_NL

Line break indicator

DEFAULT_RS

Record separator

DEFAULT_VS

Value separator

VERSION

Public Class Methods

convert(*args) click to toggle source
# File lib/midos.rb, line 70
def convert(*args)
  filter(*args) { |*| true }
end
convert_file(*args) click to toggle source
# File lib/midos.rb, line 74
def convert_file(*args)
  filter_file(*args) { |*| true }
end
filter(source, target, source_options = {}, target_options = source_options) { |*args| ... } click to toggle source
# File lib/midos.rb, line 52
def filter(source, target, source_options = {}, target_options = source_options)
  writer, size = Writer.new(target_options.merge(io: target)), 0

  Reader.parse(source, source_options) { |*args|
    writer << args and size += 1 if yield(*args)
  }

  size
end
filter_file(source_file, target_file, source_options = {}, target_options = source_options, &block) click to toggle source
# File lib/midos.rb, line 62
def filter_file(source_file, target_file, source_options = {}, target_options = source_options, &block)
  open_file(source_file, source_options) { |source|
    open_file(target_file, target_options, 'wb') { |target|
      filter(source, target, source_options, target_options, &block)
    }
  }
end
open_file(filename, options = {}, mode = 'rb', &block) click to toggle source
# File lib/midos.rb, line 86
def open_file(filename, options = {}, mode = 'rb', &block)
  options[:encoding] ||= DEFAULT_ENCODING
  File.open_file(filename, options, mode, &block)
end
uniq(*args) click to toggle source
# File lib/midos.rb, line 78
def uniq(*args)
  uniq_wrapper { |block| filter(*args, &block) }
end
uniq_file(*args) click to toggle source
# File lib/midos.rb, line 82
def uniq_file(*args)
  uniq_wrapper { |block| filter_file(*args, &block) }
end

Private Class Methods

uniq_wrapper() { |lambda| ... } click to toggle source
# File lib/midos.rb, line 93
def uniq_wrapper
  require 'nuggets/hash/seen'

  seen = Hash.seen
  yield lambda { |id, *| !seen[id] }
end