Class: CommandLine

Inherits:
Object show all
Extended by:
ClassMethods
Includes:
Assertions, Constants, Examples
Defined in:
app/models/command_line.rb

Direct Known Subclasses

CommandLineScript

Defined Under Namespace

Modules: Assertions, ClassMethods, Constants, Examples

Instance Method Summary collapse

Methods included from ClassMethods

path_of_command

Methods included from Assertions

#assert_post_conditions, #assert_pre_conditions

Constructor Details

#initialize(command, description = nil, help_source = nil) ⇒ CommandLine

Returns a new instance of CommandLine.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/command_line.rb', line 21

def initialize(command, description=nil, help_source=nil)
	if /\//.match(command) then # pathname
		@path=command
	else
		@type=ShellCommands.new('bash -c "type '+command+'"').output
		@whereis=ShellCommands.new("whereis "+command).output
		@path=@whereis.split(' ')[2]
	end #if
	@description=description
	@help_source=help_source
	@file_type=	ShellCommands.new("file -b "+@path).output
	@mime_type=	ShellCommands.new("file -b --mime "+@path).output
	@dpkg="grep "#{@path}$"  /var/lib/*/info/*.list"
	if @mime_type=='application/octet' then
		@basename=File.basename(path,File.extname(path))
		@version=ShellCommands.new(@basename+" --version").output
		@v=ShellCommands.new(basename+" -v").output
		@man=ShellCommands.new("man "+@basename).output
		@info=ShellCommands.new("info "+@basename).output
		@help=ShellCommands.new(@basename+" --help").output
		@h=ShellCommands.new(@basename+" -h").output
	end #if
end

Instance Method Details

#ruby_mimeObject

mime/types in a ruby library


45
46
47
48
49
# File 'app/models/command_line.rb', line 45

def ruby_mime
    plaintext = MIME::Types[@mime_type]
    # returns [text/plain, text/plain]
    text      = plaintext.first
end