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
71 def convert(*args)
72   filter(*args) { |*| true }
73 end
convert_file(*args) click to toggle source
   # File lib/midos.rb
75 def convert_file(*args)
76   filter_file(*args) { |*| true }
77 end
filter(source, target, source_options = {}, target_options = source_options) { |*args| ... } click to toggle source
   # File lib/midos.rb
53 def filter(source, target, source_options = {}, target_options = source_options)
54   writer, size = Writer.new(target_options.merge(io: target)), 0
55 
56   Reader.parse(source, source_options) { |*args|
57     writer << args and size += 1 if yield(*args)
58   }
59 
60   size
61 end
filter_file(source_file, target_file, source_options = {}, target_options = source_options, &block) click to toggle source
   # File lib/midos.rb
63 def filter_file(source_file, target_file, source_options = {}, target_options = source_options, &block)
64   open_file(source_file, source_options) { |source|
65     open_file(target_file, target_options, 'wb') { |target|
66       filter(source, target, source_options, target_options, &block)
67     }
68   }
69 end
open_file(filename, options = {}, mode = 'rb', &block) click to toggle source
   # File lib/midos.rb
87 def open_file(filename, options = {}, mode = 'rb', &block)
88   options[:encoding] ||= DEFAULT_ENCODING
89   File.open_file(filename, options, mode, &block)
90 end
uniq(*args) click to toggle source
   # File lib/midos.rb
79 def uniq(*args)
80   uniq_wrapper { |block| filter(*args, &block) }
81 end
uniq_file(*args) click to toggle source
   # File lib/midos.rb
83 def uniq_file(*args)
84   uniq_wrapper { |block| filter_file(*args, &block) }
85 end

Private Class Methods

uniq_wrapper() { |lambda| ... } click to toggle source
   # File lib/midos.rb
94 def uniq_wrapper
95   require 'nuggets/hash/seen'
96 
97   seen = Hash.seen
98   yield lambda { |id, *| !seen[id] }
99 end