Module: Leetcoder::Helpers::Utils
- Included in:
- Commands, Download, Submission
- Defined in:
- lib/leetcoder/leetcoder/helpers/utils.rb
Constant Summary collapse
- LANGS_EXT =
{ bash: 'sh', c: 'c', cpp: 'cpp', csharp: 'cs', golang: 'go', java: 'java', javascript: 'js', kotlin: 'kt', mysql: 'sql', php: 'php', python: 'py', python3: 'py', ruby: 'rb', rust: 'rs', scala: 'scala', swift: 'swift' }.freeze
Instance Method Summary collapse
- #create_directory(name) ⇒ Object
-
#create_file(file_path) ⇒ Object
create an empty file and return the path ex: create_file(‘~/leetcode/secret.txt’).
- #lang_to_ext(lang) ⇒ Object
- #store_cookie ⇒ Object
Instance Method Details
#create_directory(name) ⇒ Object
29 30 31 |
# File 'lib/leetcoder/leetcoder/helpers/utils.rb', line 29 def create_directory(name) FileUtils.mkdir_p(name).first end |
#create_file(file_path) ⇒ Object
create an empty file and return the path ex: create_file(‘~/leetcode/secret.txt’)
35 36 37 38 39 |
# File 'lib/leetcoder/leetcoder/helpers/utils.rb', line 35 def create_file(file_path) FileUtils.mkdir_p(file_path.match(%r{.*(?=/)})[0]).then do FileUtils.touch(file_path).first end end |
#lang_to_ext(lang) ⇒ Object
25 26 27 |
# File 'lib/leetcoder/leetcoder/helpers/utils.rb', line 25 def lang_to_ext(lang) LANGS_EXT[lang.to_sym] end |
#store_cookie ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/leetcoder/leetcoder/helpers/utils.rb', line 41 def puts 'Please paste your leetcode cookie below:' print ':>' = $stdin.gets("\n").chomp File.write(create_file(COOKIE_FILE), Base64.urlsafe_encode64()) puts "\nCookie is saved successfully! You can now access protected resources." end |