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
- #file_exists?(path) ⇒ Boolean
- #parent_exists?(path) ⇒ Boolean
-
#reader_like?(obj) ⇒ Boolean
Returns true if
objis close enough to an IO object for Nokogiri to parse as one. -
#writer_like?(obj) ⇒ Boolean
Returns true if
objis close enough to an IO object for Nokogiri to write to.
Instance Method Details
#file_exists?(path) ⇒ 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
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.
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.
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 |