Module: BerkeleyLibrary::Util::Files

Extended by:
Files
Included in:
TIND::MARC::XMLReader, TIND::MARC::XMLWriter, Files
Defined in:
lib/berkeley_library/util/files.rb

Overview

TODO: Move this to berkeley_library-util

Instance Method Summary collapse

Instance Method Details

#file_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/berkeley_library/util/files.rb', line 9

def file_exists?(path)
  (path.respond_to?(:exist?) && path.exist?) ||
    (path.respond_to?(:to_str) && File.exist?(path))
end

#parent_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/berkeley_library/util/files.rb', line 14

def parent_exists?(path)
  path.respond_to?(:parent) && path.parent.exist? ||
    path.respond_to?(:to_str) && Pathname.new(path).parent.exist?
end

#reader_like?(obj) ⇒ Boolean

Returns true if obj is close enough to an IO object for Nokogiri to parse as one.

Parameters:

  • obj (Object)

    the object that might be an IO

Returns:

  • (Boolean)

See Also:



24
25
26
# File 'lib/berkeley_library/util/files.rb', line 24

def reader_like?(obj)
  obj.respond_to?(:read) && obj.respond_to?(:close)
end

#writer_like?(obj) ⇒ Boolean

Returns true if obj is close enough to an IO object for Nokogiri to write to.

Parameters:

  • obj (Object)

    the object that might be an IO

Returns:

  • (Boolean)


32
33
34
# File 'lib/berkeley_library/util/files.rb', line 32

def writer_like?(obj)
  obj.respond_to?(:write) && obj.respond_to?(:close)
end