Class: Argument

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

Constant Summary collapse

@@argumental =
{}
@@required =
{}

Instance Method Summary collapse

Constructor Details

#initialize(arguments, error) ⇒ Argument

Returns a new instance of Argument.



8
9
10
11
# File 'lib/aml/argument.rb', line 8

def initialize(arguments,error)
	@@error = error
	parse(arguments)
end

Instance Method Details

#clear_requiredObject



44
45
46
# File 'lib/aml/argument.rb', line 44

def clear_required
	@@required = {}
end

#create(name, value) ⇒ Object



48
49
50
# File 'lib/aml/argument.rb', line 48

def create(name,value)
	@@argumental[name.to_sym] = value.strip #if(value.length > 0)
end

#create_if_empty(name, value) ⇒ Object



52
53
54
# File 'lib/aml/argument.rb', line 52

def create_if_empty(name,value)
	create(name,value) if @@argumental.select{|k,v| k.to_s == name}.count == 0
end

#defined(name) ⇒ Object



60
61
62
# File 'lib/aml/argument.rb', line 60

def defined(name)
	@@argumental.select{|k,v| k.to_s == name}.count > 0
end

#delete(name) ⇒ Object



76
77
78
# File 'lib/aml/argument.rb', line 76

def delete(name)
	@@argumental = @@argumental.select{|k,v| k.to_s != name}
end

#has_requirements?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/aml/argument.rb', line 29

def has_requirements?
	@@required.each do|key,hash|
		hash[:defined] = true if(@@argumental.select{|k,v| k.to_s == key.to_s}.count == 1)
	end
	@@required.select{|k,v| v[:defined] == false}.count == 0 ? true : false
end

#hashObject



21
22
23
# File 'lib/aml/argument.rb', line 21

def hash
	return @@argumental
end

#missing_requiredObject



36
37
38
39
40
41
42
# File 'lib/aml/argument.rb', line 36

def missing_required
	message = []
	@@required.select{|k,v| v[:defined] == false}.each do |attribute,hash|
		message << hash[:message]
	end
	message
end

#parse(arguments) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/aml/argument.rb', line 13

def parse(arguments)
	arguments = arguments.split('--')
	arguments.each do |argument|
		string = argument.split(' ')
		create(string[0],string[1..string.count].join(' ')) if argument.strip.length > 0
	end
end

#read(name) ⇒ Object



56
57
58
# File 'lib/aml/argument.rb', line 56

def read(name)
	@@argumental[name.to_sym]
end

#required(name, message) ⇒ Object



25
26
27
# File 'lib/aml/argument.rb', line 25

def required(name,message)
	@@required[name.to_sym] = {:message=>message.strip, :defined=>false}
end

#update(name, value) ⇒ Object



64
65
66
# File 'lib/aml/argument.rb', line 64

def update(name,value)
	create(name,value)
end

#update_append(name, value) ⇒ Object



68
69
70
# File 'lib/aml/argument.rb', line 68

def update_append(name,value)
	create(name,"#{value}#{read(name)}")
end

#update_prepend(name, value) ⇒ Object



72
73
74
# File 'lib/aml/argument.rb', line 72

def update_prepend(name,value)
	create(name,"#{read(name)}#{value}")
end