class DirModel::Import::Path

Attributes

current_path[R]
index[R]
path[R]

Public Class Methods

new(dir_path) click to toggle source
# File lib/dir_model/import/path.rb, line 9
def initialize(dir_path)
  @path, @index = dir_path, -1
  reset!
end

Public Instance Methods

end?() click to toggle source
# File lib/dir_model/import/path.rb, line 27
def end?
  index.nil?
end
next_path() click to toggle source
# File lib/dir_model/import/path.rb, line 31
def next_path
  ruby_path[index+1]
end
previous_path() click to toggle source
# File lib/dir_model/import/path.rb, line 35
def previous_path
  return nil if index < 1
  ruby_path[index-1]
end
read_path() click to toggle source
# File lib/dir_model/import/path.rb, line 40
def read_path
  return if end?
  @index += 1
  @current_path = ruby_path[index]
  set_end unless current_path
  current_path
end
reset!() click to toggle source
# File lib/dir_model/import/path.rb, line 18
def reset!
  @index = -1
  @current_path = @ruby_path = nil
end
rewind() click to toggle source
# File lib/dir_model/import/path.rb, line 52
def rewind
  set_position(-1)
end
set_position(index) click to toggle source
# File lib/dir_model/import/path.rb, line 48
def set_position(index)
  @index = index
end
size() click to toggle source
# File lib/dir_model/import/path.rb, line 14
def size
  @size ||= ruby_path.size
end
start?() click to toggle source
# File lib/dir_model/import/path.rb, line 23
def start?
  index == -1
end

Protected Instance Methods

ruby_path() click to toggle source
# File lib/dir_model/import/path.rb, line 58
def ruby_path
  @ruby_path ||= ::Dir.glob("#{path}/**/*").sort
end
set_end() click to toggle source
# File lib/dir_model/import/path.rb, line 62
def set_end
  @current_path = @index = nil
end