Class: CLIPar

Inherits:
Object
  • Object
show all
Defined in:
lib/clipar.rb

Instance Method Summary collapse

Constructor Details

#initializeCLIPar

Returns a new instance of CLIPar.



6
7
8
9
# File 'lib/clipar.rb', line 6

def initialize
	detect_os
	parse_args
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth) ⇒ Object

Any parameter name passed through command line will be trated as a method



49
50
51
52
53
54
55
# File 'lib/clipar.rb', line 49

def method_missing meth
	if win?

	else
		@env["#{meth}"]
	end
end

Instance Method Details

#add_param(name, value, force = false) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/clipar.rb', line 39

def add_param name, value, force=false
	return nil if win? 
	unless force
		raise "Param '#{name}' already exists" if @env.keys.include? name
	end
	@env[name]= value
end

#detect_osObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/clipar.rb', line 24

def detect_os
	@os = case RUBY_PLATFORM
    when /cygwin|mswin|mingw|bccwin|wince|emx/
      :windows
    when /darwin/
      :mac
    else
      :linux
  end
end

#parse_argsObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/clipar.rb', line 11

def parse_args
	if win?
		@env = {}
		ARGV.each do |arg|
			key_val = arg.split("=")
			@env[key_val.first]= key_val.last
		end
	else
		@env = ENV
	end
	@env
end

#win?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/clipar.rb', line 35

def win?
	@os == :windows
end