Class: Textfile
- Inherits:
-
Object
- Object
- Textfile
- Defined in:
- lib/textfile.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#path ⇒ Object
Returns the value of attribute path.
-
#tmpdir ⇒ Object
Returns the value of attribute tmpdir.
Instance Method Summary collapse
-
#clear ⇒ Object
Removes all records.
-
#initialize(path, options = {}) ⇒ Textfile
constructor
options *
:bufsiz
- Passed to GNU sort to optimize performance. -
#intersection(textfile) ⇒ Object
Removes records not present in other textfile.
-
#merge(*textfiles) ⇒ Object
Merges the contents of other textfiles and returns self.
-
#subtract(textfile) ⇒ Object
Remove records present in other textfile.
Constructor Details
#initialize(path, options = {}) ⇒ Textfile
options
-
:bufsiz
- Passed to GNU sort to optimize performance. -
:debug
- Suppress deletion of temp files. -
:lang
- Collation sequence. -
:logger
- Logs shell commands and resulting ouput (default: STDOUT).
13 14 15 16 17 18 19 |
# File 'lib/textfile.rb', line 13 def initialize(path, = {}) @bufize = [:bufsiz] @debug = [:debug] @lang = [:lang] || 'en_US.UTF-8' @logger = [:logger] || Logger.new(STDOUT) @path = path end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
6 7 8 |
# File 'lib/textfile.rb', line 6 def debug @debug end |
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/textfile.rb', line 6 def logger @logger end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/textfile.rb', line 6 def path @path end |
#tmpdir ⇒ Object
Returns the value of attribute tmpdir.
6 7 8 |
# File 'lib/textfile.rb', line 6 def tmpdir @tmpdir end |
Instance Method Details
#clear ⇒ Object
Removes all records.
22 23 24 |
# File 'lib/textfile.rb', line 22 def clear sh "cat /dev/null > #{@path}" end |
#intersection(textfile) ⇒ Object
Removes records not present in other textfile.
27 28 29 |
# File 'lib/textfile.rb', line 27 def intersection(textfile) comm(textfile, '-12') end |
#merge(*textfiles) ⇒ Object
Merges the contents of other textfiles and returns self.
32 33 34 35 |
# File 'lib/textfile.rb', line 32 def merge(*textfiles) sh "cat #{textfiles.map(&:path).join(' ')} >> #{@path}" self.sort end |
#subtract(textfile) ⇒ Object
Remove records present in other textfile.
38 39 40 41 |
# File 'lib/textfile.rb', line 38 def subtract(textfile) # --nocheck-order, see https://bugzilla.redhat.com/show_bug.cgi?id=1001775 comm(textfile, '--nocheck-order -23') end |