Module: Midos
- Defined in:
- lib/midos/reader.rb,
lib/midos.rb,
lib/midos/base.rb,
lib/midos/writer.rb,
lib/midos/version.rb
Overview
–
#
midos – A Ruby client for MIDOS databases #
#
Copyright © 2014-2015 Jens Wille #
#
Authors: #
Jens Wille <jens.wille@gmail.com> #
#
midos is free software; you can redistribute it and/or modify it under the # terms of the GNU Affero General Public License as published by the Free # Software Foundation; either version 3 of the License, or (at your option) # any later version. #
#
midos is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for # more details. #
#
You should have received a copy of the GNU Affero General Public License # along with midos. If not, see <www.gnu.org/licenses/>. #
#
++
Defined Under Namespace
Modules: Version Classes: Base, Reader, Writer
Constant Summary collapse
- DEFAULT_RS =
Record separator
'&&&'- DEFAULT_FS =
Field separator
':'- DEFAULT_VS =
Value separator
'|'- DEFAULT_NL =
Line break indicator
'^'- DEFAULT_LE =
Line ending
"\r\n"- DEFAULT_ENCODING =
Default file encoding
'ISO-8859-1'- VERSION =
Version.to_s
Class Method Summary collapse
- .convert(*args) ⇒ Object
- .convert_file(*args) ⇒ Object
- .filter(source, target, source_options = {}, target_options = source_options) ⇒ Object
- .filter_file(source_file, target_file, source_options = {}, target_options = source_options, &block) ⇒ Object
- .open_file(filename, options = {}, mode = 'rb', &block) ⇒ Object
- .uniq(*args) ⇒ Object
- .uniq_file(*args) ⇒ Object
Class Method Details
.convert(*args) ⇒ Object
71 72 73 |
# File 'lib/midos.rb', line 71 def convert(*args) filter(*args) { |*| true } end |
.convert_file(*args) ⇒ Object
75 76 77 |
# File 'lib/midos.rb', line 75 def convert_file(*args) filter_file(*args) { |*| true } end |
.filter(source, target, source_options = {}, target_options = source_options) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/midos.rb', line 53 def filter(source, target, = {}, = ) writer, size = Writer.new(.merge(io: target)), 0 Reader.parse(source, ) { |*args| writer << args and size += 1 if yield(*args) } size end |
.filter_file(source_file, target_file, source_options = {}, target_options = source_options, &block) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/midos.rb', line 63 def filter_file(source_file, target_file, = {}, = , &block) open_file(source_file, ) { |source| open_file(target_file, , 'wb') { |target| filter(source, target, , , &block) } } end |
.open_file(filename, options = {}, mode = 'rb', &block) ⇒ Object
87 88 89 90 |
# File 'lib/midos.rb', line 87 def open_file(filename, = {}, mode = 'rb', &block) [:encoding] ||= DEFAULT_ENCODING File.open_file(filename, , mode, &block) end |
.uniq(*args) ⇒ Object
79 80 81 |
# File 'lib/midos.rb', line 79 def uniq(*args) uniq_wrapper { |block| filter(*args, &block) } end |
.uniq_file(*args) ⇒ Object
83 84 85 |
# File 'lib/midos.rb', line 83 def uniq_file(*args) uniq_wrapper { |block| filter_file(*args, &block) } end |