Class: Rozi::FileWrapperBase

Inherits:
Object
  • Object
show all
Defined in:
lib/rozi/file_wrapper_base.rb

Overview

Base class for classes that wrap file objects

Direct Known Subclasses

NameSearchTextFile, TrackFile, WaypointFile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileWrapperBase

Returns a new instance of FileWrapperBase.



27
28
29
# File 'lib/rozi/file_wrapper_base.rb', line 27

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/rozi/file_wrapper_base.rb', line 7

def file
  @file
end

Class Method Details

.open(file_path, mode = "r") ⇒ Object

Behaves like File#open, but returns/yields a WaypointFile object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rozi/file_wrapper_base.rb', line 12

def self.open(file_path, mode="r")
  file = Rozi.open_file(file_path, mode)
  wrapper = self.new(file)

  if block_given?
    begin
      return yield wrapper
    ensure
      wrapper.close unless wrapper.closed?
    end
  else
    return wrapper
  end
end

Instance Method Details

#closenil

Returns:

  • (nil)


34
35
36
# File 'lib/rozi/file_wrapper_base.rb', line 34

def close
  @file.close
end

#closed?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/rozi/file_wrapper_base.rb', line 41

def closed?
  @file.closed?
end

#rewindnil

Returns:

  • (nil)


48
49
50
# File 'lib/rozi/file_wrapper_base.rb', line 48

def rewind
  @file.rewind
end