Class: DirModel::Import::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/dir_model/import/path.rb

Overview

Csv

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir_path) ⇒ Path

Returns a new instance of Path.



9
10
11
12
# File 'lib/dir_model/import/path.rb', line 9

def initialize(dir_path)
  @path, @index = dir_path, -1
  reset!
end

Instance Attribute Details

#current_pathObject (readonly)

Returns the value of attribute current_path.



7
8
9
# File 'lib/dir_model/import/path.rb', line 7

def current_path
  @current_path
end

#indexObject (readonly)

Returns the value of attribute index.



6
7
8
# File 'lib/dir_model/import/path.rb', line 6

def index
  @index
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/dir_model/import/path.rb', line 5

def path
  @path
end

Instance Method Details

#end?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/dir_model/import/path.rb', line 27

def end?
  index.nil?
end

#next_pathObject



31
32
33
# File 'lib/dir_model/import/path.rb', line 31

def next_path
  ruby_path[index+1]
end

#previous_pathObject



35
36
37
38
# File 'lib/dir_model/import/path.rb', line 35

def previous_path
  return nil if index < 1
  ruby_path[index-1]
end

#read_pathObject



40
41
42
43
44
45
46
# 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!Object



18
19
20
21
# File 'lib/dir_model/import/path.rb', line 18

def reset!
  @index = -1
  @current_path = @ruby_path = nil
end

#rewindObject



52
53
54
# File 'lib/dir_model/import/path.rb', line 52

def rewind
  set_position(-1)
end

#set_position(index) ⇒ Object



48
49
50
# File 'lib/dir_model/import/path.rb', line 48

def set_position(index)
  @index = index
end

#sizeObject



14
15
16
# File 'lib/dir_model/import/path.rb', line 14

def size
  @size ||= ruby_path.size
end

#start?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/dir_model/import/path.rb', line 23

def start?
  index == -1
end