class Mixml::Application::SelectCommand

Command that selects nodes

Attributes

suppress_output[RW]

@return [Boolean] Suppress automatic output of result

Public Class Methods

new(method, args = ARGV) click to toggle source

Initialize a new command

@param method [Symbol] Command method @param args [Array<String>] Command arguments

Calls superclass method
# 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

Public Instance Methods

before(args, options) click to toggle source

Invoked before the command is executed

@param args [Array<String>] Arguments from the command line @param options [Commander::Command::Options] Options from the command line

# File lib/mixml/application.rb, line 71
def before(args, options)
end
execute(args, options) click to toggle source

Run the command

@param args [Array<String>] Arguments from the command line @param options [Commander::Command::Options] Options from the command line

# File lib/mixml/application.rb, line 44
def execute(args, options)
    before args, options

    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() click to toggle source

Parameters for command execution

@return [Array] Parameters

# File lib/mixml/application.rb, line 63
def parameters
    []
end