Class: File

Inherits:
Object show all
Defined in:
lib/developwithpassion_expander/file.rb

Class Method Summary collapse

Class Method Details

.open_for_read(file) ⇒ Object



2
3
4
5
6
# File 'lib/developwithpassion_expander/file.rb', line 2

def self.open_for_read(file)
  File.open(file,'r').each do|line|
    yield line
  end
end

.open_for_write(file) ⇒ Object



26
27
28
29
30
# File 'lib/developwithpassion_expander/file.rb', line 26

def self.open_for_write(file)
  File.open(file,'w') do|new_file|
    yield new_file
  end
end

.read_all_text(file) ⇒ Object



8
9
10
# File 'lib/developwithpassion_expander/file.rb', line 8

def self.read_all_text(file)
  File.read_all_text_after_skipping_lines(file,0)
end

.read_all_text_after_skipping_lines(file, number_of_lines_to_skip) ⇒ Object



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

def self.read_all_text_after_skipping_lines(file,number_of_lines_to_skip)
  index = 1
  contents = ''

  if File.exist?(file)
    File.open_for_read(file) do |line|
      contents += line if index > number_of_lines_to_skip
      index+=1
    end
  end

  return contents
end