class ClassDocuShower

#

Colour-related code will be stored here.

#
#

require 'class_docu_shower/version/version.rb'

#

Constants

DEFAULT_FILE
#

DEFAULT_FILE

#
ENCODING_TO_USE
#

ENCODING_TO_USE

#
FORBIDDEN_CHARACTERS
#

FORBIDDEN_CHARACTERS

#
N
VERSION
#

ClassDocuShower::VERSION

#

Public Class Methods

[](i) click to toggle source
#

ClassDocuShower[]

#
# File lib/class_docu_shower/class_docu_shower.rb, line 282
def self.[](i)
  ClassDocuShower.new(i)
end
new( i = nil, run_already = true ) { || ... } click to toggle source
#

initialize

The first argument should be a .rb file.

The second argument can be :silent, in which case we will be silent rather than verbose.

#
# File lib/class_docu_shower/class_docu_shower.rb, line 56
def initialize(
    i           = nil,
    run_already = true
  )
  be_silent
  reset
  set_files(i)
  if run_already.is_a? Hash # Intercept hash here.
    if run_already.has_key? :verbose
      @be_verbose = run_already[:verbose]
      run_already = true
    end
  else
    case run_already
    when :silent
      be_silent
      run_already = true
    when :no_colours
      @use_colours = false
      run_already = true
    end
  end
  if block_given?
    yielded = yield
    case yielded
    when :do_not_report_the_filename
      @report_the_filename = false
    end
  end
  run if run_already
end

Public Instance Methods

be_silent() click to toggle source
#

be_silent

#
# File lib/class_docu_shower/class_docu_shower.rb, line 123
def be_silent
  @be_verbose = false
end
be_verbose() click to toggle source
#

be_verbose

#
# File lib/class_docu_shower/class_docu_shower.rb, line 116
def be_verbose
  @be_verbose = true
end
file?() click to toggle source
#

file?

#
# File lib/class_docu_shower/class_docu_shower.rb, line 130
def file?
  @file.to_s
end
files()
Alias for: files?
files?() click to toggle source
#

files?

#
# File lib/class_docu_shower/class_docu_shower.rb, line 191
def files?
  @files
end
Also aliased as: files
lightblue(i) click to toggle source
#

lightblue

#
# File lib/class_docu_shower/colours.rb, line 26
def lightblue(i)
  ::Colours.lightblue(i)
end
orange(i) click to toggle source
#

orange

#
# File lib/class_docu_shower/colours.rb, line 12
def orange(i)
  ::Colours.orange(i)
end
process() click to toggle source
#

process

This method contains the in-class logic.

#
# File lib/class_docu_shower/class_docu_shower.rb, line 208
def process
  @files.each {|file|
    show_file_header(file)
    read_in_file(file)
    process_dataset
    show_result
    e
  }
end
process_dataset() click to toggle source
#

process_dataset

#
# File lib/class_docu_shower/class_docu_shower.rb, line 221
def process_dataset
  reset_usher_object
  if @data
    @data.each {|entry| # @data is an Array.
      if entry.include? FORBIDDEN_CHARACTERS # Reject leading '# ===' parts.
        @usher.toggle if @usher
      else
        # ================================================================= #
        # Else add the entry. We should not use .lstrip on it because
        # that way we can preserve the original indent.
        # ================================================================= #
        entry.delete!('#') # .lstrip
        if use_colours? and Object.const_defined?(:Colours)
          if entry.start_with? ' ==='
            entry = orange(entry)
          elsif entry.include? 'Usage examples:'
            entry = lightblue(entry)
          end
        end
        @usher << entry if @usher
      end
    }
    @result = @usher._ if @usher
  end
end
read_in_file(this_file = @file) click to toggle source
#

read_in_file

We determine @data here.

#
# File lib/class_docu_shower/class_docu_shower.rb, line 153
def read_in_file(this_file = @file)
  if File.exist? this_file
    @data = File.readlines(this_file, :encoding => ENCODING_TO_USE)
  else # We should report.
    result = 'We could not find a file at '+sfile(this_file)+','
    result = Colours.remove_colours(result) unless use_colours?
    opn; e result
    result = 'thus can not check whether it has an documentation.'
    result = Colours.remove_colours(result) unless use_colours?
    opn; e result
  end
end
reset() click to toggle source
#

reset (reset tag)

#
# File lib/class_docu_shower/class_docu_shower.rb, line 91
def reset
  @data   = nil
  if Object.const_defined? :Usher
    @usher = Usher.new
  else
    @usher = nil
  end
  @result = nil
  @use_colours = true
  @report_the_filename = true
end
reset_usher_object() click to toggle source
#

reset_usher_object

#
# File lib/class_docu_shower/class_docu_shower.rb, line 106
def reset_usher_object
  if @usher
    @usher.reset
    @usher.allow_n_changes = 1
  end
end
result?() click to toggle source
#

result?

#
# File lib/class_docu_shower/class_docu_shower.rb, line 169
def result?
  @result
end
run() click to toggle source
#

run (run tag)

#
# File lib/class_docu_shower/class_docu_shower.rb, line 275
def run
  process
end
set_files(i = DEFAULT_FILE) click to toggle source
#

set_files

#
# File lib/class_docu_shower/class_docu_shower.rb, line 250
def set_files(i = DEFAULT_FILE)
  i = DEFAULT_FILE if i.nil?
  # i = i.to_s.dup if i
  i = [i] unless i.is_a? Array # Must always be an Array.
  i.flatten! # But keep it flattened.
  @files = i
end
sfile(i = '') click to toggle source
#

sfile

#
# File lib/class_docu_shower/class_docu_shower.rb, line 198
def sfile(i = '')
  i = Colours.sfile(i) if use_colours?
  return i
end
show_file_header(i) click to toggle source
#

show_file_header

This method will show the header, with an introduction like “From file bla”.

#
# File lib/class_docu_shower/class_docu_shower.rb, line 264
def show_file_header(i)
  if @report_the_filename#
    result = 'From file '+sfile(i)+':'+N+N
    result = Colours.remove_colours(result) unless use_colours?
    e result
  end
end
show_result() click to toggle source
#

show_result

#
# File lib/class_docu_shower/class_docu_shower.rb, line 176
def show_result
  if @be_verbose # We will be chatty here, aka, verbose.
    result = 'From the file '+sfile(file?)+' we '
    result = Colours.remove_colours(result) unless use_colours?
    opn; e result
    result = 'can show this result:'
    result = Colours.remove_colours(result) unless use_colours?
    opn; e result
  end 
  show_the_result
end
show_the_result() click to toggle source
#

show_the_result

#
# File lib/class_docu_shower/class_docu_shower.rb, line 137
def show_the_result
  e @result if result?
end
slateblue(i) click to toggle source
#

slateblue

#
# File lib/class_docu_shower/colours.rb, line 19
def slateblue(i)
  ::Colours.slateblue(i)
end
use_colours?() click to toggle source
#

use_colours?

#
# File lib/class_docu_shower/class_docu_shower.rb, line 144
def use_colours?
  @use_colours
end