Class: Pandocomatic::ConvertListCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/pandocomatic/command/convert_list_command.rb

Overview

A Command with sub commands

Instance Attribute Summary collapse

Attributes inherited from Command

#errors, #index

Instance Method Summary collapse

Methods inherited from Command

#debug?, #directory?, #dry_run?, #errors?, #file_modified?, #index_to_s, #make_quiet, #modified_only?, #quiet?, reset, #run, #runnable?, #src_root, #uncount

Constructor Details

#initializeConvertListCommand

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

#subcommandsCommand[]



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
# 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?

    CommandPrinter.new(self).print unless quiet?
    run if !dry_run? && runnable?

    @subcommands.each(&:execute)
  end
end

Instance Method Details

#all_errorsError[]

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

#countObject

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

#executeObject

Execute this ConvertListCommand



89
90
91
92
93
94
95
96
# File 'lib/pandocomatic/command/convert_list_command.rb', line 89

def execute
  return if @subcommands.empty?

  CommandPrinter.new(self).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_sString

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