Module: Mutation

Defined in:
lib/rft/mutation.rb

Class Method Summary collapse

Class Method Details

.append_text(to_write) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/rft/mutation.rb', line 13

def self.append_text(to_write)
  puts "Append text to " + to_write + ' :'
  new_text = STDIN.gets.chomp
  File.open(to_write, "a+") do |line|
    line.puts "\n" + "Following text was added at: " +Time.now.inspect + " \n"+ new_text + "\n"
  end
end

.clear_text(to_clear) ⇒ Object



33
34
35
# File 'lib/rft/mutation.rb', line 33

def self.clear_text(to_clear)
  File.open(to_clear, "w").syswrite('')
end

.copy(to_copy, new_name) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/rft/mutation.rb', line 65

def self.copy(to_copy, new_name)
  arr_lines = IO.readlines(to_copy)
  rep_file = File.new(new_name, "w");
    for rep in 0...arr_lines.length do
      rep_file.syswrite(arr_lines[rep])
    end
end

.create(to_create) ⇒ Object



3
4
5
# File 'lib/rft/mutation.rb', line 3

def self.create(to_create)
  File.open(to_create, "w");
end

.del(to_delete) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/rft/mutation.rb', line 97

def self.del(to_delete)
  if to_delete.is_a? String
    File.delete(to_delete)
  elsif to_delete.is_a? Array
    to_delete.each do |to_del|
      File.delete(to_del)
    end
  end
end

.end_of_line(to_add, end_line) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rft/mutation.rb', line 21

def self.end_of_line(to_add, end_line)
  arr_lines = IO.readlines(to_add)
  arr_lines.collect! do |ending|
    ending += end_line + "\n"
  end
  #puts arr_lines
  end_file = File.new(to_add, "w+")
  for ender in 0...arr_lines.length
    end_file.syswrite(arr_lines[ender])
  end
end

.overwrite_text(to_overwrite) ⇒ Object



7
8
9
10
11
# File 'lib/rft/mutation.rb', line 7

def self.overwrite_text(to_overwrite)
  puts "Write text to " + to_write + ' :'
  new_text = STDIN.gets.chomp
  File.open(to_write, "w").syswrite(new_text)
end

.remove(to_file, to_remove) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/rft/mutation.rb', line 73

def self.remove(to_file, to_remove)
  if to_file.is_a? String
    arr_lines = IO.readlines(to_file)
    arr_lines.each do |remover|
      remover.gsub!(/#{to_remove}/, '' )
    end
    rep_file = File.new(to_file, "w");
    for rep in 0...arr_lines.length do
      rep_file.syswrite(arr_lines[rep])
    end
  elsif to_remove.is_a? Array
    to_remove.each do |removement|
      arr_lines = IO.readlines(removement)
      arr_lines.each do |remover|
        remover.gsub!(/#{to_remove}/, '' )
      end
      rep_file = File.new(removement, "w");
      for rep in 0...arr_lines.length do
        rep_file.syswrite(arr_lines[rep])
      end
    end
  end
end

.rename(from, to) ⇒ Object



37
38
39
# File 'lib/rft/mutation.rb', line 37

def self.rename(from, to)
  File.rename(from, to)
end

.replace(to_rep, with_word) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rft/mutation.rb', line 41

def self.replace(to_rep, with_word)
  if to_rep.is_a? String
    arr_lines = IO.readlines(to_rep)
    arr_lines.each do |replacer|
      replacer.gsub!(/#{ARGV[2]}/, with_word )
    end
    rep_file = File.new(to_rep, "w");
    for rep in 0...arr_lines.length do
      rep_file.syswrite(arr_lines[rep])
    end
  elsif to_rep.is_a? Array
    to_rep.each do |replacement|
      arr_lines = IO.readlines(replacement)
      arr_lines.each do |replacer|
        replacer.gsub!(/#{ARGV[2]}/, with_word )
      end
      rep_file = File.new(replacement, "w");
      for rep in 0...arr_lines.length do
        rep_file.syswrite(arr_lines[rep])
      end
    end
  end
end