Class: Redcar::FilterCommand::OutputFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/filter_command/output_format.rb

Overview

A means of displaying text. New output formats can be defined by extending OutputFormat and implementing the type and format methods

Direct Known Subclasses

DiscardOutput, InsertOutput, ReplaceInput, ShowText

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.formatsObject

A Hash of all known formats



9
10
11
# File 'lib/filter_command/output_format.rb', line 9

def self.formats
  @types ||= {}
end

.supported_types(*names) ⇒ Object

The generator method for formats



14
15
16
17
18
19
20
21
# File 'lib/filter_command/output_format.rb', line 14

def self.supported_types(*names)
  if names.any?
    names.each {|n| OutputFormat.formats[n] = self }
    @supported_types = supported_types + names
  else
    @supported_types ||= []
  end
end

Instance Method Details

#edit_tab_focussed?Boolean

A check whether an editable tab is currently focussed in Redcar

Returns:

  • (Boolean)


24
25
26
# File 'lib/filter_command/output_format.rb', line 24

def edit_tab_focussed?
  tab and tab.is_a?(Redcar::EditTab)
end

#format(text, type) ⇒ Object

Where the work happens! This method is called when there is text to be processed

Parameters:

  • text (String)

    the text to be formatted

  • type (String)

    a name of a defined output type for the current class



57
58
59
# File 'lib/filter_command/output_format.rb', line 57

def format text, type
  raise "A format method has not been defined by #{self.class.name}"
end

#missing_edit_tab(type) ⇒ Object

The error message indicating that the currently selected output format requires the current tab to be an editable tab



45
46
47
# File 'lib/filter_command/output_format.rb', line 45

def missing_edit_tab type
  Redcar::Application::Dialog.message_box("To use the #{type} output format, the current tab must be an edit tab.")
end

#newlineObject

A newline character (platform-specific)



35
36
37
38
39
40
41
# File 'lib/filter_command/output_format.rb', line 35

def newline
  if Redcar.platform == :win
    newline = "\r\n"
  else
    newline = "\n"
  end
end

#tabObject

The currently focussed tab



29
30
31
32
# File 'lib/filter_command/output_format.rb', line 29

def tab
  win = Redcar.app.focussed_window
  win.focussed_notebook_tab
end

#typeObject

A name or list of names of supported output formats for the current class



50
51
52
# File 'lib/filter_command/output_format.rb', line 50

def type
  raise "A name has not been defined by #{self.class.name}. This text is displayed in the Filter Command speedbar."
end