Class: Pik::ScriptFile

Inherits:
Object show all
Defined in:
lib/pik/scripts/script_file.rb

Direct Known Subclasses

BashFile, BatchFile, PsFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) {|_self| ... } ⇒ ScriptFile

, mode=:new)

Yields:

  • (_self)

Yield Parameters:



7
8
9
10
11
# File 'lib/pik/scripts/script_file.rb', line 7

def initialize(file) #, mode=:new)
  @file = Pathname.new(file.to_s + extname) 
  @file_data = [header]
  yield self if block_given?
end

Instance Attribute Details

#file_dataObject

Returns the value of attribute file_data.



5
6
7
# File 'lib/pik/scripts/script_file.rb', line 5

def file_data
  @file_data
end

#file_nameObject

Returns the value of attribute file_name.



5
6
7
# File 'lib/pik/scripts/script_file.rb', line 5

def file_name
  @file_name
end

#ruby_dirObject

Returns the value of attribute ruby_dir.



5
6
7
# File 'lib/pik/scripts/script_file.rb', line 5

def ruby_dir
  @ruby_dir
end

Instance Method Details

#<<(cmd) ⇒ Object



39
40
41
# File 'lib/pik/scripts/script_file.rb', line 39

def << (cmd)
  @file_data <<  cmd
end

#echo(string = '.') ⇒ Object



21
22
23
24
25
# File 'lib/pik/scripts/script_file.rb', line 21

def echo(string='.')
  string = ' ' + string unless string == '.'
  @file_data << "ECHO#{string}"
  self
end

#extnameObject



17
18
19
# File 'lib/pik/scripts/script_file.rb', line 17

def extname
  raise
end

#pathObject



13
14
15
# File 'lib/pik/scripts/script_file.rb', line 13

def path
  @file
end

#remove_line(re) ⇒ Object



27
28
29
# File 'lib/pik/scripts/script_file.rb', line 27

def remove_line(re)
  @file_data.reject!{ |i| i =~ re }
end

#to_sObject



31
32
33
# File 'lib/pik/scripts/script_file.rb', line 31

def to_s
  @file_data.join("\n")
end

#writeObject



35
36
37
# File 'lib/pik/scripts/script_file.rb', line 35

def write
  File.open(@file, 'w+'){|f| f.puts self.to_s }
end