Class: QiitaUpLoad
- Inherits:
-
Object
- Object
- QiitaUpLoad
- Defined in:
- lib/qiita_org/upload.rb
Instance Method Summary collapse
- #get_file_path(src) ⇒ Object
-
#initialize(src, option, os) ⇒ QiitaUpLoad
constructor
A new instance of QiitaUpLoad.
- #input_url_to_org(paths) ⇒ Object
- #open_file_dir(paths) ⇒ Object
- #open_qiita ⇒ Object
- #upload ⇒ Object
Constructor Details
#initialize(src, option, os) ⇒ QiitaUpLoad
Returns a new instance of QiitaUpLoad.
10 11 12 13 14 15 |
# File 'lib/qiita_org/upload.rb', line 10 def initialize(src, option, os) @src = src @option = (option == "qiita" || option == "open")? "public" : option @os = os @fileopen = FileOpen.new(@os) end |
Instance Method Details
#get_file_path(src) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/qiita_org/upload.rb', line 36 def get_file_path(src) lines = File.readlines(src) files = [] lines.each do |line| if path = line.match(/\[\[(.+)\]\[file:(.+)\]\]/) || line.match(/\[\[file:(.+)\]\]/) if path[2] == nil files << path[1] else files << path[2] end end end return files end |
#input_url_to_org(paths) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/qiita_org/upload.rb', line 83 def input_url_to_org(paths) lines = File.readlines(@src) conts = File.read(@src) id = conts.match(/\#\+qiita_#{@option}: (.+)/)[1] paths.each do |path| file_name = File.basename(path).strip url = get_file_url(id, file_name) lines.each_with_index do |line, i| if line.match(/\[\[file:#{path}\]\]/) lines[i] = "[[#{url}][file:#{path}]]\n" end end end File.write(@src, lines.join) end |
#open_file_dir(paths) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/qiita_org/upload.rb', line 52 def open_file_dir(paths) previous_paths = [] previous_paths << File.join(paths[0].split("/")[0..-2]) @fileopen.file_open(File.join(paths[0].split("/")[0..-2])) paths.each do |path| dir_path = File.join(path.split("/")[0..-2]) unless previous_paths.include?(dir_path) previous_paths << dir_path @fileopen.file_open(dir_path) end end end |
#open_qiita ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/qiita_org/upload.rb', line 66 def open_qiita() conts = File.read(@src) id = conts.match(/\#\+qiita_#{option}: (.+)/)[1] @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config() if @option == "teams" ErrorMassage.new().teams_url_error(@teams_url) end qiita = (@option == "teams") ? @teams_url : "https://qiita.com/" path = "api/v2/items/#{id}" items = AccessQiita.new(@access_token, qiita, path).access_qiita() @fileopen.file_open(items["url"]) end |
#upload ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/qiita_org/upload.rb', line 17 def upload() paths = GetFilePath.new(@src).get_file_path() #paths = get_file_path(@src) unless paths.empty? showfile = ShowFile.new(paths, @src, @option, @os) showfile.open_file_dir() #open_file_dir(paths) showfile.open_qiita() #open_qiita() puts "Overwrite file URL's on #{@src}? (y/n)".green ans = STDIN.getch if ans == "y" showfile.input_url_to_org() end else puts "file path is empty.".red end end |