Class: CorrectHorseBatteryStaple::Writer::File

Inherits:
Base show all
Defined in:
lib/correct_horse_battery_staple/writer/file.rb

Overview

base class for file-based stores

Direct Known Subclasses

Csv, Isam, Isamkd, Json, Marshal

Instance Attribute Summary collapse

Attributes inherited from Base

#dest, #options

Instance Method Summary collapse

Methods inherited from Base

#write_corpus

Methods included from Common

#array_sample, #logger, #random_in_range, #random_number, #set_sample

Methods inherited from CorrectHorseBatteryStaple::Writer

make_writer, write

Constructor Details

#initialize(dest, options = {}) ⇒ File

Returns a new instance of File.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/correct_horse_battery_staple/writer/file.rb', line 8

def initialize(dest, options = {})
  super

  @do_close = false
  if dest.respond_to?(:write)
    self.io = dest
  else
    if ["/dev/stdout", "-"].include?(dest)
      self.io = STDOUT
    else
      self.io = open(dest, openmode)
      @do_close = true
    end
  end
end

Instance Attribute Details

#ioObject

Returns the value of attribute io.



6
7
8
# File 'lib/correct_horse_battery_staple/writer/file.rb', line 6

def io
  @io
end

Instance Method Details

#closeObject



24
25
26
27
28
29
30
# File 'lib/correct_horse_battery_staple/writer/file.rb', line 24

def close
  return unless @do_close
  self.io.close rescue nil
ensure
  self.io = nil
  @do_close = false
end