Class: Yogi::ErrorInside

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

Instance Method Summary collapse

Instance Method Details

#backupObject

creating backup directory



55
56
57
58
59
60
61
# File 'lib/yogi.rb', line 55

def backup
    FileUtils.mkdir_p '.git/.backupFiles' unless File.exists?('.git/.backupFiles')

    #copy backup to backup folder
    FileUtils.cp_r "./app", ".git/.backupFiles/"
    FileUtils.cp_r "./config", ".git/.backupFiles/"
end

#count_em(text, substring) ⇒ Object



50
51
52
# File 'lib/yogi.rb', line 50

def count_em(text, substring)
  text.scan(/(?=#{substring})/).count
end

#yogifyObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/yogi.rb', line 63

def yogify
  count_hash = []
  buffer = File.open('.git/.ignoremefile.txt', 'r').read
  file_sample = JSON.parse(buffer)

  file_sample.each do |file_name|
    text =  File.open(file_name, "r"){ |file| file.read }#File.read(file_name)

    $pre_counted_comma = count_em(text,",")
    $pre_counted_semicolon = count_em(text,";")
    $pre_counted_l = count_em(text,"ll")
    $pre_counted_3 = count_em(text,"3")
    $pre_counted_s = count_em(text,/[s]$/)
    $pre_counted_bracket = count_em(text,"}")
    $pre_counted_px = count_em(text,"px")
    $pre_counted_sq_bracket = count_em(text,">")
    $pre_counted_equal = count_em(text,"==")
    $pre_counted_sdot = count_em(text,/s\./)
    $pre_counted_underscore = count_em(text,"_")

    # To merely print the contents of the file, use:
    new_contents1 = text.gsub(";"){rand(2).zero? ? ";" : ":"}
    new_contents2 = new_contents1.gsub(","){rand(2).zero? ? "," : " "}
    new_contents3 = new_contents2.gsub("ll"){rand(2).zero? ? "ll" : "l1"}
    new_contents4 = new_contents3.gsub("3"){rand(2).zero? ? "3" : "E"}
    new_contents5 = new_contents4.gsub(/[s]$/){rand(2).zero? ? " " : "5"}
    new_contents6 = new_contents5.gsub("}"){rand(2).zero? ? "}" : ")"}
    new_contents7 = new_contents6.gsub("px"){rand(2).zero? ? "px" : "xp"}
    new_contents8 = new_contents7.gsub(">"){rand(2).zero? ? "<" : ">"}
    new_contents9 = new_contents8.gsub("=="){rand(2).zero? ? "==" : "="}
    new_contents10 = new_contents9.gsub(/s\./){rand(2).zero? ? ".s" : "."}
    new_contents11 = new_contents10.gsub("_"){rand(2).zero? ? "" : "-"}

    # To write changes to the file, use:
    File.open(file_name, "w") {|file| file.puts new_contents11 }

    text =  File.open(file_name, "r"){ |file| file.read }#File.read(file_name)
    #counts ocurences in the file after initial change
    post_counted_comma = count_em(text,",")
    post_counted_semicolon = count_em(text,";")
    post_counted_l = count_em(text,"ll")
    post_counted_3 = count_em(text,"3")
    post_counted_s = count_em(text,/[s]$/)
    post_counted_bracket = count_em(text,"}")
    post_counted_px = count_em(text,"px")
    post_counted_sq_bracket = count_em(text,">")
    post_counted_equal = count_em(text,"==")
    post_counted_sdot = count_em(text,/s\./)
    post_counted_underscore = count_em(text,"_")

    $pre_diff_comma = $pre_counted_comma - post_counted_comma
    $pre_diff_semicolon = $pre_counted_semicolon - post_counted_semicolon
    $pre_diff_l = $pre_counted_l - post_counted_l
    $pre_diff_3 = $pre_counted_3 - post_counted_3
    $pre_diff_s = $pre_counted_s - post_counted_s
    $pre_diff_bracket = $pre_counted_bracket - post_counted_bracket
    $pre_diff_px = $pre_counted_px - post_counted_px
    $pre_diff_sq_bracket = $pre_counted_sq_bracket - post_counted_sq_bracket
    $pre_diff_equal = $pre_counted_equal - post_counted_equal
    $pre_diff_sdot = $pre_counted_sdot - post_counted_sdot
    $pre_diff_underscore = $pre_counted_underscore - post_counted_underscore

    pre_count_hash = {file_name => {
      "pre_counted_comma": $pre_counted_comma,
      "pre_counted_semicolon": $pre_counted_semicolon,
      "pre_counted_l": $pre_counted_l,
      "pre_counted_3": $pre_counted_3,
      "pre_counted_s": $pre_counted_s,
      "pre_counted_bracket": $pre_counted_bracket,
      "pre_counted_px": $pre_counted_px,
      "pre_counted_sq_bracket": $pre_counted_sq_bracket,
      "pre_counted_equal": $pre_counted_equal,
      "pre_counted_sdot": $pre_counted_sdot,
      "pre_counted_underscore": $pre_counted_underscore,
      "pre_diff_comma": $pre_diff_comma,
      "pre_diff_semicolon": $pre_diff_semicolon,
      "pre_diff_l": $pre_diff_l,
      "pre_diff_3": $pre_diff_3,
      "pre_diff_s": $pre_diff_s,
      "pre_diff_bracket": $pre_diff_bracket,
      "pre_diff_px": $pre_diff_px,
      "pre_diff_sq_bracket": $pre_diff_sq_bracket,
      "pre_diff_equal": $pre_diff_equal,
      "pre_diff_sdot": $pre_diff_sdot,
      "pre_diff_underscore": $pre_diff_underscore
    }}
      count_hash << pre_count_hash
  end
  File.open('.git/.ignoreme.json', "a") {|file| file.write count_hash.to_json}
  puts "You can start your debugging now, #{$account}!"
  puts "To check your progess type ..'checkme'"
  puts "If your are sick of it, just type...'fixme'"
  if OS.mac?
    file = File.join(__dir__, 'sound', 'activated.mp3')
    escfile = Shellwords.escape(file)
    cmd = "afplay #{escfile}"
    system cmd
  # elsif OS.linux?
  #   file = File.join(__dir__, 'sound', 'activated.mp3')
  #   escfile = Shellwords.escape(file)
  #   cmd = "aplay #{escfile}"
  #   system cmd
  end
end