Class: Mixml::Application::SelectCommand
- Inherits:
-
Commander::Command
- Object
- Commander::Command
- Mixml::Application::SelectCommand
- Defined in:
- lib/mixml/application.rb
Overview
Command that selects nodes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#suppress_output ⇒ Boolean
Suppress automatic output of result.
Instance Method Summary collapse
-
#before(args, options) ⇒ Object
Invoked before the command is executed.
-
#execute(args, options) ⇒ Object
Run the command.
-
#initialize(method, args = ARGV) ⇒ SelectCommand
constructor
Initialize a new command.
-
#parameters ⇒ Array
Parameters for command execution.
Constructor Details
#initialize(method, args = ARGV) ⇒ SelectCommand
Initialize a new command
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mixml/application.rb', line 19 def initialize(method, args = ARGV) super(method) @method = method @selectors = [] option '-x', '--xpath STRING', String, 'XPath expression to select nodes' do |value| @selectors << ->(tool) { xpath value } end option '-c', '--css STRING', String, 'CSS rule to select nodes' do |value| @selectors << ->(tool) { css value } end when_called self, :execute end |
Instance Attribute Details
#suppress_output ⇒ Boolean
Returns Suppress automatic output of result.
13 14 15 |
# File 'lib/mixml/application.rb', line 13 def suppress_output @suppress_output end |
Instance Method Details
#before(args, options) ⇒ Object
Invoked before the command is executed
71 72 |
# File 'lib/mixml/application.rb', line 71 def before(args, ) end |
#execute(args, options) ⇒ Object
Run the command
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mixml/application.rb', line 44 def execute(args, ) before args, if @suppress_output then $tool.print = false $tool.save = false end $tool.work(args) do @selectors.each do |selector| selection = instance_eval(&selector) selection.send name, *parameters end end end |
#parameters ⇒ Array
Parameters for command execution
63 64 65 |
# File 'lib/mixml/application.rb', line 63 def parameters [] end |