Class: ShowFile
- Inherits:
-
Object
- Object
- ShowFile
- Defined in:
- lib/qiita_org/show_file_and_url.rb
Instance Method Summary collapse
-
#initialize(paths, src, mode) ⇒ ShowFile
constructor
A new instance of ShowFile.
- #open_file_dir ⇒ Object
- #show_file_url ⇒ Object
Constructor Details
#initialize(paths, src, mode) ⇒ ShowFile
Returns a new instance of ShowFile.
5 6 7 8 9 |
# File 'lib/qiita_org/show_file_and_url.rb', line 5 def initialize(paths, src, mode) @paths = paths @src = src @mode = (mode == "qiita" || mode == "open")? "public" : mode end |
Instance Method Details
#open_file_dir ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/qiita_org/show_file_and_url.rb', line 11 def open_file_dir() previous_paths = [] previous_paths << File.join(@paths[0].split("/")[0..-2]) system "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 system "open #{dir_path}" end end end |
#show_file_url ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/qiita_org/show_file_and_url.rb', line 24 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 |