Class: Mercenary::Presenter

### Home Classes Methods

### In Files

- lib/mercenary/presenter.rb

### Parent

Object

### Methods

- ::new
- #command_header
- #command_presentation
- #method_missing
- #options_presentation
- #subcommands_presentation
- #usage_presentation

### Class/Module Index

Quicksearch

- Mercenary
- Mercenary::Command
- Mercenary::Option
- Mercenary::Presenter
- Mercenary::Program

No matching classes.

# Mercenary::Presenter

### Attributes

command[RW]

### Public Class Methods

new(command) click to toggle source

Public: Make a new Presenter

command - a Mercenary::Command to present

Returns nothing

    # File lib/mercenary/presenter.rb, line 10
    def initialize(command)
      @command = command
    end

### Public Instance Methods

command_header() click to toggle source

Public: Builds the command header, including the command identity and description

Returns the command header as a String

    # File lib/mercenary/presenter.rb, line 40
    def command_header
      header = "#{command.identity}"
      header << " -- #{command.description}" if command.description
      header
    end

command_presentation() click to toggle source

Public: Builds a string representation of the whole command

Returns the string representation of the whole command

    # File lib/mercenary/presenter.rb, line 49
    def command_presentation
      msg = []
      msg << command_header
      msg << "Usage:"
      msg << usage_presentation

      if opts = options_presentation
        msg << "Options:\n#{opts}"
      end
      if subcommands = subcommands_presentation
        msg << "Subcommands:\n#{subcommands_presentation}"
      end
      msg.join("\n\n")
    end

method_missing(meth, *args, &block) click to toggle source

Public: Turn a print_* into a *_presentation or freak out

meth - the method being called args - an array of arguments passed to the missing method block - the block passed to the missing method

Returns the value of whatever function is called

    # File lib/mercenary/presenter.rb, line 71
    def method_missing(meth, *args, &block)
      if meth.to_s =~ /^print_(.+)$/
        send("#{$1.downcase}_presentation")
      else
        super # You *must* call super if you don't handle the method,
              # otherwise you'll mess up Ruby's method lookup.
      end
    end

options_presentation() click to toggle source

Public: Builds a string representation of the options

Returns the string representation of the options

    # File lib/mercenary/presenter.rb, line 24
    def options_presentation
      return nil unless command.options.size > 0
      command.options.map(&:to_s).join("\n")
    end

subcommands_presentation() click to toggle source

Public: Builds a string representation of the subcommands

Returns the string representation of the subcommands

    # File lib/mercenary/presenter.rb, line 32
    def subcommands_presentation
      return nil unless command.commands.size > 0
      command.commands.values.uniq.map(&:summarize).join("\n")
    end

usage_presentation() click to toggle source

Public: Builds a string representation of the command usage

Returns the string representation of the command usage

    # File lib/mercenary/presenter.rb, line 17
    def usage_presentation
      "  #{command.syntax}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.