Class: BatchFile
Instance Attribute Summary collapse
-
#file_data ⇒ Object
Returns the value of attribute file_data.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#ruby_dir ⇒ Object
Returns the value of attribute ruby_dir.
Class Method Summary collapse
Instance Method Summary collapse
- #call(bat) ⇒ Object
- #echo(string = '.') ⇒ Object
- #ftype(files = { 'rbfile' => @ruby_exe, 'rbwfile' => @rubyw_exe }) ⇒ Object
- #header ⇒ Object
-
#initialize(file, mode = :new) {|_self| ... } ⇒ BatchFile
constructor
A new instance of BatchFile.
- #path ⇒ Object
- #remove_line(re) ⇒ Object
- #set(items) ⇒ Object
- #to_s ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(file, mode = :new) {|_self| ... } ⇒ BatchFile
Returns a new instance of BatchFile.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pik/batch_file.rb', line 12 def initialize(file, mode=:new) @rubyw_exe = 'rubyw.exe' @ruby_exe = 'ruby.exe' @file = Pathname.new(file) case mode when :open @file_data = File.read(@file).split("\n") when :new @file_data = [header] end yield self if block_given? end |
Instance Attribute Details
#file_data ⇒ Object
Returns the value of attribute file_data.
10 11 12 |
# File 'lib/pik/batch_file.rb', line 10 def file_data @file_data end |
#file_name ⇒ Object
Returns the value of attribute file_name.
10 11 12 |
# File 'lib/pik/batch_file.rb', line 10 def file_name @file_name end |
#ruby_dir ⇒ Object
Returns the value of attribute ruby_dir.
10 11 12 |
# File 'lib/pik/batch_file.rb', line 10 def ruby_dir @ruby_dir end |
Class Method Details
.open(file) {|bf| ... } ⇒ Object
4 5 6 7 8 |
# File 'lib/pik/batch_file.rb', line 4 def self.open(file) bf = new(file, :open) yield bf if block_given? bf end |
Instance Method Details
#call(bat) ⇒ Object
42 43 44 45 |
# File 'lib/pik/batch_file.rb', line 42 def call(bat) @file_data << "CALL #{bat}\n" self end |
#echo(string = '.') ⇒ Object
52 53 54 55 56 |
# File 'lib/pik/batch_file.rb', line 52 def echo(string='.') string = ' ' + string unless string == '.' @file_data << "ECHO#{string}" self end |
#ftype(files = { 'rbfile' => @ruby_exe, 'rbwfile' => @rubyw_exe }) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/pik/batch_file.rb', line 35 def ftype(files={ 'rbfile' => @ruby_exe, 'rbwfile' => @rubyw_exe }) files.sort.each do |filetype, open_with| @file_data << "FTYPE #{filetype}=#{open_with} \"%1\" %*\n" end self end |
#header ⇒ Object
29 30 31 32 33 |
# File 'lib/pik/batch_file.rb', line 29 def header string = "@ECHO OFF\n\n" string << ":: This batch file generated by Pik, the\n" string << ":: Ruby Manager for Windows\n" end |
#path ⇒ Object
25 26 27 |
# File 'lib/pik/batch_file.rb', line 25 def path @file end |
#remove_line(re) ⇒ Object
58 59 60 |
# File 'lib/pik/batch_file.rb', line 58 def remove_line(re) @file_data.reject!{ |i| i =~ re } end |
#set(items) ⇒ Object
47 48 49 50 |
# File 'lib/pik/batch_file.rb', line 47 def set(items) items.each{|k,v| @file_data << "SET #{k}=#{v}" } self end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/pik/batch_file.rb', line 62 def to_s @file_data.join("\n") end |