Class: GrassGis::Module
- Inherits:
-
Object
- Object
- GrassGis::Module
- Defined in:
- lib/grassgis/module.rb
Overview
Instance Method Summary collapse
-
#initialize(id, options = {}) ⇒ Module
constructor
A new instance of Module.
- #method_missing(method, *args) ⇒ Object
- #name ⇒ Object
-
#run(*args) ⇒ Object
Executes the command (with given arguments) returns a SysCmd object (with status, status_value, output, error_output methods).
Constructor Details
#initialize(id, options = {}) ⇒ Module
Returns a new instance of Module.
14 15 16 17 18 |
# File 'lib/grassgis/module.rb', line 14 def initialize(id, = {}) @id = id.to_s @parent = [:parent] @context = [:context] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Method Details
#name ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/grassgis/module.rb', line 20 def name if @parent "#{@parent.name}.#{@id}" else @id end end |
#run(*args) ⇒ Object
Executes the command (with given arguments) returns a SysCmd object (with status, status_value, output, error_output methods)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/grassgis/module.rb', line 30 def run(*args) stdin = nil cmd = SysCmd.command name do args.each do |arg| case arg when Hash arg.each do |key, value| next if value.nil? case value when Array value = value*"," when String if value.include?("\n") raise "Cannot pass multiple options through STDIN" if stdin stdin = Support.unindent(value) value = "-" input stdin end end option key.to_s, equal_value: value end else option arg end end end if @context @context.execute cmd end cmd end |