Class: MyHelp::Control
- Inherits:
-
Object
- Object
- MyHelp::Control
- Defined in:
- lib/my_help/my_help_controll.rb
Instance Method Summary collapse
- #delete_help(file) ⇒ Object
- #disp_opts(conts) ⇒ Object
- #edit_help(file) ⇒ Object
- #init_help(file) ⇒ Object
-
#initialize ⇒ Control
constructor
A new instance of Control.
- #list_all ⇒ Object
- #list_help(file) ⇒ Object
- #select_item(help, item) ⇒ Object
- #set_help_dir_if_not_exists ⇒ Object
- #show_item(file, item) ⇒ Object
- #upload_help(file) ⇒ Object
Constructor Details
#initialize ⇒ Control
Returns a new instance of Control
4 5 6 7 8 9 10 |
# File 'lib/my_help/my_help_controll.rb', line 4 def initialize() @template_dir = File.("../../templates", __FILE__) @exe_dir = File.("../../exe", __FILE__) @local_help_dir = File.join(ENV['HOME'],'.my_help') # @mini_account = File set_help_dir_if_not_exists end |
Instance Method Details
#delete_help(file) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/my_help/my_help_controll.rb', line 103 def delete_help(file) file = File.join(@local_help_dir,file+'.org') print "Are you sure to delete "+file.blue+"?[Ynq] ".red case STDIN.gets.chomp when 'Y' begin FileUtils.rm(file,:verbose=>true) rescue => error puts error.to_s.red end when 'n', 'q' ; exit end end |
#disp_opts(conts) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/my_help/my_help_controll.rb', line 53 def disp_opts( conts ) col = 0 conts.each_pair do |key, item| col_length = case col when 0; print item.rjust(5)+", " when 1; print item.ljust(15)+": " else; print item end col += 1 end print("\n") end |
#edit_help(file) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/my_help/my_help_controll.rb', line 79 def edit_help(file) p target_help = File.join(@local_help_dir,file+'.org') if local_help_entries.member?(file+'.org') system "emacs #{target_help}" else puts "file #{target_help} does not exits in #{@local_help_dir}." puts "init #{file} first." end end |
#init_help(file) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/my_help/my_help_controll.rb', line 89 def init_help(file) if file.nil? puts "specify NAME".red exit end p target_help=File.join(@local_help_dir,file+'.org') if File::exists?(target_help) puts "File exists. delete it first to initialize it." exit end p template = File.join(@template_dir,'help_template.org') FileUtils::Verbose.cp(template,target_help) end |
#list_all ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/my_help/my_help_controll.rb', line 66 def list_all print "List all helps\n" local_help_entries.each do |file| file_path=File.join(@local_help_dir,file) title = file.split('.')[0] help = auto_load(file_path) next if help.nil? desc = help[:head][:cont].split("\n")[0] print title.rjust(10).blue print ": #{desc}\n".blue end end |
#list_help(file) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/my_help/my_help_controll.rb', line 44 def list_help(file) file_path=File.join(@local_help_dir,file+'.org') help = auto_load(file_path) help.each_pair do |key, conts| print conts[:cont] if key==:head disp_opts( conts[:opts] ) end end |
#select_item(help, item) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/my_help/my_help_controll.rb', line 32 def select_item(help, item) o_key = '' help.each_pair do |key, cont| next if key==:license or key==:head if cont[:opts][:short] == item or cont[:opts][:long] == item o_key = key break end end o_key end |
#set_help_dir_if_not_exists ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/my_help/my_help_controll.rb', line 12 def set_help_dir_if_not_exists return if File::exists?(@local_help_dir) FileUtils.mkdir_p(@local_help_dir, :verbose=>true) Dir.entries(@template_dir).each{|file| next if file=='help_template.org' file_path=File.join(@local_help_dir,file) next if File::exists?(file_path) FileUtils.cp((File.join(@template_dir,file)),@local_help_dir,:verbose=>true) } end |
#show_item(file, item) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/my_help/my_help_controll.rb', line 23 def show_item(file, item) file_path=File.join(@local_help_dir,file+'.org') help = auto_load(file_path) select = select_item(help, item) print help[:head][:cont] puts '-'*5+"\n"+select.to_s.red print help[select][:cont] end |
#upload_help(file) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/my_help/my_help_controll.rb', line 117 def upload_help(file) p target_help = File.join(@local_help_dir,file+'.org') puts "miniのuser_nameを入力してください." p user_name = STDIN.gets.chomp puts "保存するディレクトリ名を入力してください." p directory_name = STDIN.gets.chomp if local_help_entries.member?(file+'.org') # if target_help.empty?(file+'.org') # system "scp #{@local_help_dir} tomoko_y@mini:~/our_help/member/tomoko" # else system "scp #{target_help} #{user_name}@mini:~/our_help/member/#{directory_name}" puts "後は,miniでgitにpushしてください." # end else puts "file #{target_help} does not exits in #{@local_help_dir}." puts "init #{file} first." end end |