Class: ShowFile

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

Instance Method Summary collapse

Constructor Details

#initialize(paths, src, mode, os) ⇒ ShowFile



8
9
10
11
12
13
14
# File 'lib/qiita_org/show_file_and_url.rb', line 8

def initialize(paths, src, mode, os)
  @paths = paths
  @src = src
  @mode = (mode == "qiita" || mode == "open") ? "public" : mode
  @os = os
  @fileopen = FileOpen.new(@os)
end

Instance Method Details

#input_url_to_orgObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/qiita_org/show_file_and_url.rb', line 89

def input_url_to_org()
  lines = File.readlines(@src)
  conts = File.read(@src)
  id = conts.match(/\#\+qiita_#{@mode}: (.+)/)[1]

  @paths.each do |path|
    file_name = File.basename(path).strip
    geturl = GetFileUrl.new(id, file_name, @mode)
    url = geturl.get_file_url()
    lines.each_with_index do |line, i|
      if line.match(/\[\[file:#{path}\]\]/)
        #lines[i] = "[[file:# {path}][# {url}]]\n"
        lines[i] = "[[#{url}][file:#{path}]]\n"
      end
    end
  end
  #p lines
  File.write(@src, lines.join)
end

#open_file_dirObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/qiita_org/show_file_and_url.rb', line 16

def open_file_dir()
  previous_paths = []
  previous_paths << File.join(@paths[0].split("/")[0..-2])
  @fileopen.file_open(File.join(@paths[0].split("/")[0..-2]))

  #    if @os == "mac"
  #      system "open # {File.join(@paths[0].split("/")[0..-2])}"
  #    elsif @os == "windows"
  #      system "explorer.exe # {File.join(@paths[0].split("/")[0..-2])}"
  #    else
  #      system "open # {File.join(@paths[0].split("/")[0..-2])}"
  #      system "xdg-open # {File.join(@paths[0].split("/")[0..-2])}"
  #    end

  @paths.each do |path|
    dir_path = File.join(path.split("/")[0..-2])
    unless previous_paths.include?(dir_path)
      previous_paths << dir_path
      #system "open # {dir_path}"
      @fileopen.file_open(dir_path)

      #        if @os == "mac"
      #          system "open # {dir_path}"
      #        elsif @os == "windows"
      #          system "explorer.exe # {dir_path}"
      #        else
      #          system "open # {dir_path}"
      #          system "xdg-open # {dir_path}"
      #        end
    end
  end
end

#open_qiitaObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/qiita_org/show_file_and_url.rb', line 49

def open_qiita()
  conts = File.read(@src)
  id = conts.match(/\#\+qiita_#{@mode}: (.+)/)[1]

  @access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
  if @mode == "teams"
    ErrorMassage.new().teams_url_error(@teams_url)
  end

  qiita = (@mode == "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"])
=begin
  if @os == "mac"
    system "open # {items["url"]}"
  elsif @os == "windows"
    system "explorer.exe # {items["url"]}"
  else
    system "open # {items["url"]}"
    system "xdg-open # {items["url"]}"
  end
=end

end

#show_file_urlObject



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/qiita_org/show_file_and_url.rb', line 76

def show_file_url()
  conts = File.read(@src)
  id = conts.match(/\#\+qiita_#{@mode}: (.+)/)[1]

  @paths.each do |path|
    file_name = File.basename(path).strip
    geturl = GetFileUrl.new(id, file_name, @mode)
    url = geturl.get_file_url()
    puts "#{file_name}'s URL".green
    puts url
  end
end