ghedsh 1.1.40 → 2.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,469 +3,404 @@ require 'fileutils'
3
3
  require 'octokit'
4
4
  require 'optparse'
5
5
  require 'json'
6
- require 'actions/system'
7
6
  require 'version'
7
+ require 'rainbow'
8
+ require 'tty-spinner'
9
+ require 'tty-prompt'
8
10
 
9
11
  class Sys
10
12
  attr_reader :client
11
13
  attr_reader :memory
12
- LIST = ['repos', 'exit', 'orgs','help', 'people','teams', 'cd ', 'cd repo ','commits','forks', 'add_team_member ','new team ','rm team ','new repository ','new assignment ','clone ', 'issues',
13
- 'version', 'cat ', 'groups', 'files', 'assignments','new issue ', 'open issue', 'new ','open ', 'close issue', 'new group ', 'rm group', 'rm ', 'do ', 'info','make','add repo',
14
- 'add group','rm repository ', 'new people info ', 'private ', 'people info ', 'new issue comment ', "rm people info", "change repo",'add students','new relation','rm clone files'].sort
14
+ LIST = %w[clear exit repos new_repo new_team rm_team rm_repo new_issue issues clone invite_outside_collaborators
15
+ rm_cloned new_eval foreach foreach_try files commits orgs invite_member_from_file invite_member people teams cd open bash].sort
15
16
 
16
- def initialize()
17
- @memory=[]
17
+ def initialize
18
+ @memory = []
18
19
  end
19
20
 
20
21
  # CACHE READLINE METHODS
21
22
  def add_history(value)
22
23
  @memory.push(value)
23
- self.write_memory
24
+ write_memory
24
25
  end
25
26
 
26
27
  def quit_history(value)
27
28
  @memory.pop(value)
28
- self.write_memory
29
+ write_memory
29
30
  end
30
31
 
31
- def add_history_str(mode,value)
32
- if mode==1
32
+ def add_history_str(mode, value)
33
+ if mode == 1
33
34
  value.each do |i|
34
35
  @memory.push(i[0])
35
- self.write_memory
36
+ write_memory
36
37
  end
37
38
  end
38
- if mode==2
39
+ if mode == 2
39
40
  value.each do |i|
40
41
  @memory.push(i)
41
- self.write_memory
42
+ write_memory
42
43
  end
43
44
  end
44
45
  end
46
+
45
47
  def write_memory
46
- history=(LIST+@memory).sort
47
- comp = proc { |s| history.grep( /^#{Regexp.escape(s)}/ ) }
48
- Readline.completion_append_character = ""
48
+ history = (LIST + @memory).sort
49
+ comp = proc { |s| history.grep(/^#{Regexp.escape(s)}/) }
50
+ Readline.completion_append_character = ''
49
51
  Readline.completion_proc = comp
50
52
  end
51
53
 
52
- def load_memory(path,config)
53
- if File.exist?("#{path}/ghedsh-#{config["User"]}-history")
54
- source=File.read("#{path}/ghedsh-#{config["User"]}-history")
55
- s=source.split("\n")
54
+ def load_memory(path, config)
55
+ if File.exist?("#{path}/ghedsh-#{config['User']}-history")
56
+ source = File.read("#{path}/ghedsh-#{config['User']}-history")
57
+ s = source.split("\n")
56
58
  s.each do |i|
57
59
  Readline::HISTORY.push(i)
58
60
  end
59
61
  else
60
- File.write("#{path}/ghedsh-#{config["User"]}-history","")
62
+ File.write("#{path}/ghedsh-#{config['User']}-history", '')
61
63
  end
62
64
  end
63
65
 
64
- def save_memory(path,config)
65
- mem= Readline::HISTORY.to_a
66
- me=""
66
+ def save_memory(path, config)
67
+ mem = Readline::HISTORY.to_a
68
+ me = ''
67
69
  mem.each do |i|
68
- me=me+i.to_s+"\n"
70
+ me = me + i.to_s + "\n"
69
71
  end
70
- File.write("#{path}/ghedsh-#{config["User"]}-history",me)
72
+ File.write("#{path}/ghedsh-#{config['User']}-history", me)
71
73
  end
72
74
 
73
-
74
75
  def write_initial_memory
75
- history=LIST+memory
76
- comp = proc { |s| LIST.grep( /^#{Regexp.escape(s)}/ ) }
77
-
78
- Readline.completion_append_character = ""
76
+ history = LIST + memory
77
+ comp = proc { |s| LIST.grep(/^#{Regexp.escape(s)}/) }
78
+ Readline.completion_append_character = ''
79
79
  Readline.completion_proc = comp
80
80
  end
81
81
  # END CACHE READLINE METHODS
82
82
 
83
- #Loading initial configure, if ghedsh path doesnt exist, call the create method
84
- def load_config(configure_path,argv_token)
83
+ # Loading initial configure, if ghedsh path doesnt exist, call the create method
84
+ def load_config(configure_path, argv_token)
85
85
  if File.exist?(configure_path)
86
- if argv_token==nil
87
- token=self.get_login_token(configure_path)
88
- else
89
- token=argv_token
90
- end
86
+ token = if argv_token.nil?
87
+ get_login_token(configure_path)
88
+ else
89
+ argv_token
90
+ end
91
91
  json = File.read("#{configure_path}/ghedsh-cache.json")
92
- config=JSON.parse(json)
92
+ config = JSON.parse(json)
93
93
 
94
- if token!=nil
95
- @client=self.login(token)
96
- config["User"]=@client.login
97
- userslist=self.load_users(configure_path)
94
+ if !token.nil?
95
+ @client = login(token)
96
+ config['User'] = @client.login
97
+ config['user_url'] = @client.web_endpoint.to_s << @client.login.to_s
98
+ userslist = load_users(configure_path)
98
99
 
99
- if userslist["users"].detect {|f| f["#{config["User"]}"] }==nil
100
- self.add_users(configure_path,"#{config["User"]}"=>token)
101
- end
102
- if argv_token!=nil
103
- self.save_token(configure_path,argv_token)
100
+ if userslist['users'].detect { |f| f[(config['User']).to_s] }.nil?
101
+ add_users(configure_path, (config['User']).to_s => token)
104
102
  end
103
+ save_token(configure_path, argv_token) unless argv_token.nil?
105
104
  return config
106
105
  else
107
- return self.set_loguin_data_sh(config,configure_path)
106
+ return set_loguin_data_sh(config, configure_path)
108
107
  end
109
108
  else
110
- self.create_config(configure_path)
111
- load_config(configure_path,argv_token)
109
+ create_config(configure_path)
110
+ load_config(configure_path, argv_token)
112
111
  end
113
112
  end
114
113
 
115
- #loading configure with --user mode
114
+ # loading configure with --user mode
116
115
  def load_config_user(configure_path, user)
117
116
  if File.exist?(configure_path)
118
- list=self.load_users(configure_path)
119
- userFound=list["users"].detect {|f| f["#{user}"]}
120
- if userFound!=nil
121
- self.clear_cache(configure_path)
117
+ list = load_users(configure_path)
118
+ userFound = list['users'].detect { |f| f[user.to_s] }
119
+ if !userFound.nil?
120
+ clear_cache(configure_path)
122
121
  json = File.read("#{configure_path}/ghedsh-cache.json")
123
- config=JSON.parse(json)
124
- @client=self.login(userFound["#{user}"])
125
- config["User"]=@client.login
126
- self.save_token(configure_path,userFound["#{user}"])
122
+ config = JSON.parse(json)
123
+ @client = login(userFound[user.to_s])
124
+ config['User'] = @client.login
125
+ config['user_url'] = @client.web_endpoint.to_s << @client.login.to_s
126
+ save_token(configure_path, userFound[user.to_s])
127
127
  return config
128
128
  else
129
- puts "User not found"
129
+ puts 'User not found'
130
130
  return nil
131
131
  end
132
132
  else
133
133
  puts "No user's history is available"
134
- return nil
134
+ nil
135
135
  end
136
136
  end
137
137
 
138
138
  def load_users(path)
139
- json=File.read("#{path}/ghedsh-users.json")
140
- users=JSON.parse(json)
141
- return users
139
+ json = File.read("#{path}/ghedsh-users.json")
140
+ users = JSON.parse(json)
141
+ users
142
142
  end
143
143
 
144
- # USER=1
145
- # ORGS=2
146
- # USER_REPO=10
147
- # ORGS_REPO=3
148
- # TEAM=4
149
- # ASSIG=6
150
- # TEAM_REPO=5
151
-
152
144
  def return_deep(path)
153
145
  json = File.read("#{path}/ghedsh-cache.json")
154
- cache=JSON.parse(json)
155
- deep=1
156
- case
157
- when cache["Team"]!=nil
158
- if cache["Repo"]!=nil
159
- deep=5
160
- else
161
- deep=4
162
- end
163
- when cache["Team"]==nil
164
- if cache["Org"]!=nil
165
- if cache["Repo"]!=nil
166
- deep=3
167
- else
168
- if cache["Assig"]!=nil
169
- deep=6
170
- else
171
- deep=2
172
- end
173
- end
174
- else
175
- if cache["Repo"]!=nil
176
- deep=10
177
- else
178
- deep=1
179
- end
180
- end
181
- end
182
- return deep
146
+ cache = JSON.parse(json)
147
+ deep = User
148
+ return deep = Team unless cache['Team'].nil?
149
+ return deep = Organization unless cache['Org'].nil?
150
+ deep
183
151
  end
184
152
 
185
- def add_users(path,data)
186
- json=File.read("#{path}/ghedsh-users.json")
187
- users=JSON.parse(json)
188
- users["users"].push(data)
189
- File.write("#{path}/ghedsh-users.json",users.to_json)
153
+ def add_users(path, data)
154
+ json = File.read("#{path}/ghedsh-users.json")
155
+ users = JSON.parse(json)
156
+ users['users'].push(data)
157
+ File.write("#{path}/ghedsh-users.json", users.to_json)
190
158
  end
191
159
 
192
- def save_token(path,token)
193
- json=File.read("#{path}/ghedsh-users.json")
194
- login=JSON.parse(json)
195
- login["login"]=token
196
- File.write("#{path}/ghedsh-users.json",login.to_json)
160
+ def save_token(path, token)
161
+ json = File.read("#{path}/ghedsh-users.json")
162
+ login = JSON.parse(json)
163
+ login['login'] = token
164
+ File.write("#{path}/ghedsh-users.json", login.to_json)
197
165
  end
198
166
 
199
167
  def get_login_token(path)
200
- json=File.read("#{path}/ghedsh-users.json")
201
- us=JSON.parse(json)
202
- return us["login"]
168
+ json = File.read("#{path}/ghedsh-users.json")
169
+ us = JSON.parse(json)
170
+ us['login']
203
171
  end
204
172
 
205
173
  def login(token)
206
174
  begin
207
- user=Octokit::Client.new(:access_token =>token) #per_page:100
208
- user.auto_paginate=true #show all pages of any query
209
- rescue
210
- puts "Oauth error"
175
+ user = Octokit::Client.new(access_token: token) # per_page:100
176
+ user.auto_paginate = true # show all pages of any query
177
+ rescue StandardError
178
+ puts 'Oauth error'
211
179
  end
212
- return user
213
- end
214
-
215
- #initial program configure
216
- def set_loguin_data_sh(config,configure_path)
217
- puts "Insert you Access Token: "
218
- token = gets.chomp
219
- us=self.login(token)
220
- userhash=Hash.new
221
-
222
- if us!=nil
223
- puts "Login succesful as #{us.login}\n"
224
- config["User"]=us.login
225
- self.add_users(configure_path,"#{config["User"]}"=>token)
226
- self.save_token(configure_path,token)
227
- @client=us
180
+
181
+ user
182
+ end
183
+
184
+ # initial program configure
185
+ def set_loguin_data_sh(config, configure_path)
186
+ prompt = TTY::Prompt.new(enable_color: true)
187
+ username = prompt.ask('Username:', required: true)
188
+ passwd = prompt.ask('Password:', echo: false)
189
+
190
+ client = Octokit::Client.new \
191
+ login: username,
192
+ password: passwd
193
+ response = client.create_authorization(scopes: ['user', 'repo', 'admin:org', 'admin:public_key', 'admin:repo_hook', 'admin:org_hook', 'gist', 'notifications', 'delete_repo', 'admin:gpg_key'],
194
+ note: 'GitHub Education Shell auth token')
195
+ token = response[:token]
196
+ us = login(token)
197
+ userhash = {}
198
+
199
+ unless us.nil?
200
+ puts Rainbow("Successful login as #{us.login}\n").green
201
+ config['User'] = us.login
202
+ config['user_url'] = us.web_endpoint << us.login
203
+
204
+ add_users(configure_path, (config['User']).to_s => token)
205
+ save_token(configure_path, token)
206
+ @client = us
228
207
  return config
229
208
  end
230
209
  end
231
210
 
232
211
  def load_assig_db(path)
233
- if (File.exist?(path))==true
212
+ if File.exist?(path) == true
234
213
  if File.exist?("#{path}/assignments.json")
235
214
  json = File.read("#{path}/assignments.json")
236
215
  else
237
- #{"Organization":[{"name":null,"assignments":[{"name":null,"teams":{"teamid":null}}]}]}
238
- con={:orgs=>[]}
239
- File.write("#{path}/assignments.json",con.to_json)
216
+ # {"Organization":[{"name":null,"assignments":[{"name":null,"teams":{"teamid":null}}]}]}
217
+ con = { orgs: [] }
218
+ File.write("#{path}/assignments.json", con.to_json)
240
219
  json = File.read("#{path}/assignments.json")
241
220
  end
242
221
  end
243
- config=JSON.parse(json)
244
- return config
222
+ config = JSON.parse(json)
223
+ config
245
224
  end
246
225
 
247
226
  def load_people_db(path)
248
- if (File.exist?(path))==true
227
+ if File.exist?(path) == true
249
228
  if File.exist?("#{path}/ghedsh-people.json")
250
229
  json = File.read("#{path}/ghedsh-people.json")
251
230
  else
252
- con={:orgs=>[]}
253
- File.write("#{path}/ghedsh-people.json",con.to_json)
231
+ con = { orgs: [] }
232
+ File.write("#{path}/ghedsh-people.json", con.to_json)
254
233
  json = File.read("#{path}/ghedsh-people.json")
255
234
  end
256
235
  end
257
- config=JSON.parse(json)
258
- return config
236
+ config = JSON.parse(json)
237
+ config
259
238
  end
260
239
 
261
240
  def load_script(path)
262
- if (File.exist?(path))==true
263
- script = File.read("#{path}")
264
- return script.split("\n")
241
+ if File.exist?(path) == true
242
+ script = File.read(path.to_s)
243
+ script.split("\n")
265
244
  else
266
- puts "No script is found with that name"
267
- return []
245
+ puts 'No script is found with that name'
246
+ []
268
247
  end
269
248
  end
270
249
 
271
250
  def load_groups(path)
272
- if (File.exist?(path))==true
251
+ if File.exist?(path) == true
273
252
  if File.exist?("#{path}/groups.json")
274
253
  json = File.read("#{path}/groups.json")
275
254
  else
276
- con={:orgs=>[]}
277
- File.write("#{path}/groups.json",con.to_json)
255
+ con = { orgs: [] }
256
+ File.write("#{path}/groups.json", con.to_json)
278
257
  json = File.read("#{path}/groups.json")
279
258
  end
280
259
  else
281
- #path="/db/assignments.json"
282
- #json = File.read(path)
260
+ # path="/db/assignments.json"
261
+ # json = File.read(path)
283
262
  end
284
- config=JSON.parse(json)
285
- return config
263
+ config = JSON.parse(json)
264
+ config
286
265
  end
287
266
 
288
- def refresh_clonefile(path,list)
289
- if (File.exist?(path))==true
290
- File.write("#{path}/ghedsh-clonedfiles",list)
291
- end
267
+ def refresh_clonefile(path, list)
268
+ File.write("#{path}/ghedsh-clonedfiles", list) if File.exist?(path) == true
292
269
  end
293
270
 
294
271
  def load_clonefile(path)
295
- if (File.exist?(path))==true
272
+ if File.exist?(path) == true
296
273
  if File.exist?("#{path}/ghedsh-clonedfiles")
297
- files=File.read("#{path}/ghedsh-clonedfiles")
298
- files=files.delete("["); files=files.delete("]")
299
- files=files.split(",")
300
- return files
274
+ files = File.read("#{path}/ghedsh-clonedfiles")
275
+ files = files.delete('['); files = files.delete(']')
276
+ files = files.split(',')
277
+ files
301
278
  else
302
- File.write("#{path}/ghedsh-clonedfiles","")
303
- return []
279
+ File.write("#{path}/ghedsh-clonedfiles", '')
280
+ []
304
281
  end
305
282
  end
306
283
  end
307
284
 
308
285
  def create_temp(path)
309
- if (File.exist?(path))==false
310
- FileUtils.mkdir_p(path)
311
- end
286
+ FileUtils.mkdir_p(path) if File.exist?(path) == false
312
287
  end
313
288
 
314
289
  def remove_temp(path)
315
- if (File.exist?(path))==true
316
- system("rm -rf #{path}")
317
- end
290
+ system("rm -rf #{path}") if File.exist?(path) == true
318
291
  end
319
292
 
320
- def save_groups(path,data)
321
- File.write("#{path}/groups.json",data.to_json)
293
+ def save_groups(path, data)
294
+ File.write("#{path}/groups.json", data.to_json)
322
295
  end
323
296
 
324
- def save_assigs(path,data)
325
- File.write("#{path}/assignments.json",data.to_json)
297
+ def save_assigs(path, data)
298
+ File.write("#{path}/assignments.json", data.to_json)
326
299
  end
327
300
 
328
- def save_people(path,data)
329
- File.write("#{path}/ghedsh-people.json",data.to_json)
301
+ def save_people(path, data)
302
+ File.write("#{path}/ghedsh-people.json", data.to_json)
330
303
  end
331
304
 
332
- #creates all ghedsh local stuff
305
+ # creates all ghedsh local stuff
333
306
  def create_config(configure_path)
334
- con={:User=>nil,:Org=>nil,:Repo=>nil,:Team=>nil,:TeamID=>nil}
335
- us={:login=>nil, :users=>[]}
307
+ con = { User: nil, user_url: nil, Org: nil, org_url: nil, Repo: nil, repo_url: nil, Team: nil, team_url: nil, TeamID: nil }
308
+ us = { login: nil, users: [] }
336
309
  FileUtils.mkdir_p(configure_path)
337
- File.write("#{configure_path}/ghedsh-cache.json",con.to_json)
338
- File.write("#{configure_path}/ghedsh-users.json",us.to_json)
339
- puts "Confiration files created in #{configure_path}"
310
+ File.write("#{configure_path}/ghedsh-cache.json", con.to_json)
311
+ File.write("#{configure_path}/ghedsh-users.json", us.to_json)
312
+ puts "Configuration files created in #{configure_path}"
340
313
  end
341
314
 
342
-
343
- def save_cache(path,data)
344
- File.write("#{path}/ghedsh-cache.json",data.to_json)
315
+ def save_cache(path, data)
316
+ File.write("#{path}/ghedsh-cache.json", data.to_json)
345
317
  end
346
318
 
347
319
  def clear_cache(path)
348
- con={:User=>nil,:Org=>nil,:Repo=>nil,:Team=>nil,:TeamID=>nil}
349
- File.write("#{path}/ghedsh-cache.json",con.to_json)
320
+ con = { User: nil, user_url: nil, Org: nil, org_url: nil, Repo: nil, repo_url: nil, Team: nil, team_url: nil, TeamID: nil }
321
+ File.write("#{path}/ghedsh-cache.json", con.to_json)
350
322
  end
351
323
 
352
- def save_db(path,data)
324
+ def save_db(path, data)
353
325
  File.write("#{path}/db/assignments.json", data.to_json)
354
326
  end
355
327
 
356
- def save_users(path,data)
357
- File.write("#{path}/ghedsh-users.json",data.to_json)
328
+ def save_users(path, data)
329
+ File.write("#{path}/ghedsh-users.json", data.to_json)
358
330
  end
359
331
 
360
332
  def execute_bash(exp)
361
333
  system(exp)
362
334
  end
363
335
 
364
- def search_rexp(list,exp)
365
- list= list.select{|o| o.match(/#{exp}/)}
366
- return list
336
+ def search_rexp(list, exp)
337
+ list = list.select { |o| o.match(/#{exp}/) }
338
+ list
367
339
  end
368
340
 
369
- def search_rexp_peoplehash(list,exp)
370
- found=[]
371
- yes=false
341
+ def search_rexp_peoplehash(list, exp)
342
+ found = []
343
+ yes = false
372
344
  list.each do |i|
373
345
  i.each do |j|
374
- if j[1]!=nil
375
- if j[1].match(/#{exp}/)
376
- yes=true
377
- end
346
+ unless j[1].nil?
347
+ yes = true if j[1] =~ /#{exp}/
378
348
  end
379
349
  end
380
- if yes==true
350
+ if yes == true
381
351
  found.push(i)
382
- yes=false
383
- end
384
- end
385
- return found
386
- end
387
-
388
- def parse()
389
- options = {:user => nil, :token => nil, :path => nil}
390
-
391
- parser = OptionParser.new do|opts|
392
- opts.banner = "Usage: ghedsh [options]\nWith no options it runs with default configuration. Configuration files are being set in #{ENV['HOME']}/.ghedsh\n"
393
- opts.on('-t', '--token token', 'Provides a github access token by argument.') do |token|
394
- options[:token] = token;
395
- end
396
- opts.on('-c', '--configpath path', 'Give your own path for GHEDSH configuration files') do |path|
397
- options[:configpath] = path;
398
- end
399
- opts.on('-u', '--user user', 'Change your user from your users list') do |user|
400
- options[:user] = user;
401
- end
402
- opts.on('-v', '--version', 'Show the current version of GHEDSH') do
403
- puts "GitHub Education Shell v#{Ghedsh::VERSION}"
404
- exit
352
+ yes = false
405
353
  end
406
- opts.on('-h', '--help', 'Displays Help') do
407
- puts opts
408
- exit
409
- end
410
354
  end
411
-
412
- begin
413
- parser.parse!
414
- rescue
415
- puts "Argument error. Use ghedsh -h or ghedsh --help for more information about the usage of this program"
416
- exit
417
- end
418
- return options
355
+ found
419
356
  end
420
357
 
421
358
  def createTempFile(data)
422
- tempfile="temp.txt"
423
- path="#{ENV['HOME']}/.ghedsh/#{tempfile}"
424
- File.write(path,data)
425
- return path
359
+ tempfile = 'temp.txt'
360
+ path = "#{ENV['HOME']}/.ghedsh/#{tempfile}"
361
+ File.write(path, data)
362
+ path
426
363
  end
427
364
 
428
- def showcachelist(list,exp)
365
+ def showcachelist(list, exp)
429
366
  print "\n"
430
- rlist=[]
431
- options=Hash.new
432
- o=Organizations.new
433
- regex=false
434
-
435
- if exp!=nil
436
- if exp.match(/^\//)
437
- regex=true
438
- sp=exp.split('/')
439
- exp=Regexp.new(sp[1],sp[2])
367
+ rlist = []
368
+ options = {}
369
+ o = Organizations.new
370
+ regex = false
371
+
372
+ unless exp.nil?
373
+ if exp =~ /^\//
374
+ regex = true
375
+ sp = exp.split('/')
376
+ exp = Regexp.new(sp[1], sp[2])
440
377
  end
441
378
  end
442
- counter=0
443
- allpages=true
379
+ counter = 0
380
+ allpages = true
444
381
 
445
382
  list.each do |i|
446
- if regex==false
447
- if counter==100 && allpages==true
448
- op=Readline.readline("\nThere are more results. Show next repositories (press any key) or Show all repositories (press a): ",true)
449
- if op=="a"
450
- allpages=false
451
- end
452
- counter=0
383
+ if regex == false
384
+ if counter == 100 && allpages == true
385
+ op = Readline.readline("\nThere are more results. Show next repositories (press any key) or Show all repositories (press a): ", true)
386
+ allpages = false if op == 'a'
387
+ counter = 0
453
388
  end
454
389
  puts i
455
390
  rlist.push(i)
456
- counter=counter+1
391
+ counter += 1
457
392
  else
458
393
 
459
- if i.match(exp)
394
+ if i.match(exp)
460
395
  puts i
461
396
  rlist.push(i)
462
- counter=counter+1
463
- end
397
+ counter += 1
398
+ end
464
399
  end
465
400
  end
466
401
 
467
402
  if rlist.empty?
468
- puts "No repository matches with that expression"
403
+ puts 'No repository matches with that expression'
469
404
  else
470
405
  print "\n"
471
406
  puts "Repositories found: #{rlist.size}"
@@ -474,20 +409,19 @@ class Sys
474
409
 
475
410
  def loadfile(path)
476
411
  if File.exist?(path)
477
- mem=File.read(path)
478
- mem=mem.split("\n")
479
- return mem
412
+ mem = File.read(path)
413
+ mem = mem.split("\n")
414
+ mem
480
415
  else
481
- puts "File not found"
482
- return nil
416
+ puts 'File not found'
417
+ nil
483
418
  end
484
419
  end
485
420
 
486
421
  def open_url(url)
487
- case
488
- when RUBY_PLATFORM.downcase.include?("darwin")
422
+ if RUBY_PLATFORM.downcase.include?('darwin')
489
423
  system("open #{url}")
490
- when RUBY_PLATFORM.downcase.include?("linux")
424
+ elsif RUBY_PLATFORM.downcase.include?('linux')
491
425
  system("xdg-open #{url}")
492
426
  end
493
427
  end