Class: Pandocomatic::ConvertListCommand
- Defined in:
- lib/pandocomatic/command/convert_list_command.rb
Overview
A Command with sub commands
Direct Known Subclasses
Instance Attribute Summary collapse
-
#subcommands ⇒ Command[]
The subcommands of this ConvertListCommand.
Attributes inherited from Command
Instance Method Summary collapse
-
#all_errors ⇒ Error[]
Get a list of all errors generated while running this command.
-
#count ⇒ Object
The number of commands to execute when this ConvertListCommand is executed.
-
#execute ⇒ Object
Execute this ConvertListCommand.
-
#initialize ⇒ ConvertListCommand
constructor
Create a new ConvertListCommand.
-
#multiple? ⇒ Boolean
Can this command have multiple commands?.
-
#push(command) ⇒ Object
Push a command to this ConvertListCommand.
-
#skip? ⇒ Boolean
Skip this ConvertListCommand when there are no sub commands.
-
#to_s ⇒ String
A string representation of this ConvertListCommand.
Methods inherited from Command
#directory?, #dry_run?, #errors?, #file_modified?, #index_to_s, #make_quiet, #modified_only?, #quiet?, reset, #run, #runnable?, #src_root, #uncount
Constructor Details
#initialize ⇒ ConvertListCommand
Create a new ConvertListCommand
38 39 40 41 |
# File 'lib/pandocomatic/command/convert_list_command.rb', line 38 def initialize super @subcommands = [] end |
Instance Attribute Details
#subcommands ⇒ Command[]
Returns the subcommands of this ConvertListCommand.
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pandocomatic/command/convert_list_command.rb', line 34 class ConvertListCommand < Command attr_reader :subcommands # Create a new ConvertListCommand def initialize super @subcommands = [] end # Push a command to this ConvertListCommand # # @param command [Command] command to add def push(command) @subcommands.push command end # Skip this ConvertListCommand when there are no sub commands # # @return [Boolean] def skip? @subcommands.empty? end # The number of commands to execute when this ConvertListCommand # is executed. def count @subcommands.reduce(0) do |total, subcommand| total + subcommand.count end end # Get a list of all errors generated while running this command # # @return [Error[]] def all_errors @subcommands.reduce(@errors) do |total, subcommand| total + subcommand.all_errors end end # A string representation of this ConvertListCommand # # @return [String] def to_s "converting #{@subcommands.size} items:" end # Can this command have multiple commands? # # @return [Boolean] true def multiple? true end # Execute this ConvertListCommand def execute return if @subcommands.empty? description = CommandPrinter.new(self) Pandocomatic::LOG.info description description.print unless quiet? run if !dry_run? && runnable? @subcommands.each(&:execute) end end |
Instance Method Details
#all_errors ⇒ Error[]
Get a list of all errors generated while running this command
68 69 70 71 72 |
# File 'lib/pandocomatic/command/convert_list_command.rb', line 68 def all_errors @subcommands.reduce(@errors) do |total, subcommand| total + subcommand.all_errors end end |
#count ⇒ Object
The number of commands to execute when this ConvertListCommand is executed.
59 60 61 62 63 |
# File 'lib/pandocomatic/command/convert_list_command.rb', line 59 def count @subcommands.reduce(0) do |total, subcommand| total + subcommand.count end end |
#execute ⇒ Object
Execute this ConvertListCommand
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/pandocomatic/command/convert_list_command.rb', line 89 def execute return if @subcommands.empty? description = CommandPrinter.new(self) Pandocomatic::LOG.info description description.print unless quiet? run if !dry_run? && runnable? @subcommands.each(&:execute) end |
#multiple? ⇒ Boolean
Can this command have multiple commands?
84 85 86 |
# File 'lib/pandocomatic/command/convert_list_command.rb', line 84 def multiple? true end |
#push(command) ⇒ Object
Push a command to this ConvertListCommand
46 47 48 |
# File 'lib/pandocomatic/command/convert_list_command.rb', line 46 def push(command) @subcommands.push command end |
#skip? ⇒ Boolean
Skip this ConvertListCommand when there are no sub commands
53 54 55 |
# File 'lib/pandocomatic/command/convert_list_command.rb', line 53 def skip? @subcommands.empty? end |
#to_s ⇒ String
A string representation of this ConvertListCommand
77 78 79 |
# File 'lib/pandocomatic/command/convert_list_command.rb', line 77 def to_s "converting #{@subcommands.size} items:" end |