Class: Scorm::Command::Base
- Inherits:
-
Object
- Object
- Scorm::Command::Base
show all
- Defined in:
- lib/scorm/commands/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args) ⇒ Base
Returns a new instance of Base.
8
9
10
11
|
# File 'lib/scorm/commands/base.rb', line 8
def initialize(args)
@args = args
@autodetected_package = false
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
5
6
7
|
# File 'lib/scorm/commands/base.rb', line 5
def args
@args
end
|
#autodetected_package ⇒ Object
Returns the value of attribute autodetected_package.
6
7
8
|
# File 'lib/scorm/commands/base.rb', line 6
def autodetected_package
@autodetected_package
end
|
Instance Method Details
#display(msg, newline = true) ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/scorm/commands/base.rb', line 13
def display(msg, newline=true)
if newline
puts(msg)
else
print(msg)
STDOUT.flush
end
end
|
#error(msg) ⇒ Object
22
23
24
25
|
# File 'lib/scorm/commands/base.rb', line 22
def error(msg)
STDERR.puts(msg)
exit 1
end
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/scorm/commands/base.rb', line 37
def (options, default=true)
values = options.is_a?(Array) ? options : [options]
return unless opt_index = args.select { |a| values.include? a }.first
opt_position = args.index(opt_index) + 1
if args.size > opt_position && opt_value = args[opt_position]
if opt_value.include?('--')
opt_value = nil
else
args.delete_at(opt_position)
end
end
opt_value ||= default
args.delete(opt_index)
block_given? ? yield(opt_value) : opt_value
end
|
27
28
29
30
31
32
33
34
35
|
# File 'lib/scorm/commands/base.rb', line 27
def (force=true)
package = ('--package', false)
raise(CommandFailed, "You must specify a package name after --package") if package == false
unless package
raise(CommandFailed, "No package specified.\nRun this command from package folder or set it adding --package <package name>") if force
@autodetected_package = true
end
package
end
|