class RBT::Action::Statistics::ReturnCompileTimeStatistics

Public Class Methods

[](i = ARGV) click to toggle source
#

RBT::Action::Statistics::ReturnCompileTimeStatistics[]

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 193
def self.[](i = ARGV)
  new(i)
end
new( i = ARGV, run_already = true, &block ) click to toggle source
#

initialize

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 32
def initialize(
    i           = ARGV,
    run_already = true,
    &block
  )
  reset
  set_commandline_arguments(i)
  run if run_already
end

Public Instance Methods

body?() click to toggle source
#

body?

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 126
def body?
  @body
end
dataset?() click to toggle source
#

dataset?

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 70
def dataset?
  @dataset
end
does_the_main_file_exist?() click to toggle source
#

does_the_main_file_exist?

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 109
def does_the_main_file_exist?
  File.file?(main_file?)
end
empty?() click to toggle source
#

empty?

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 84
def empty?
  dataset?.empty?
end
keys()
Alias for: keys?
keys?() click to toggle source
#

keys?

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 77
def keys?
  dataset?.keys
end
Also aliased as: keys
main_file?() click to toggle source
#

main_file?

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 102
def main_file?
  RBT.file_storing_the_time_it_took_to_compile_programs
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Action#reset
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 45
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @dataset
  # ======================================================================= #
  @dataset = nil # Default value.
  # ======================================================================= #
  # === @body
  #
  # @body will contain the body of the compile-time statistics.
  # ======================================================================= #
  reset_the_body_variable
end
reset_the_body_variable() click to toggle source
#

reset_the_body_variable

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 63
def reset_the_body_variable
  @body = ''.dup
end
return_the_header() click to toggle source
#

return_the_header

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 91
def return_the_header
  'Program name'.ljust(32)+ # header part1
  'Compile time [sec] '+    # header part2
  'Compile time [min]'+     # header part3
  ' Archive file size'+     # header part4
  ' #'                      # header part5
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 133
def run
  try_to_load_up_the_dataset
  if dataset?
    reset_the_body_variable
    # =================================================================== #
    # Need to sort this dataset by duration next. The programs that
    # took the longest to compile, will be on "top" of the Array.
    # =================================================================== #
    sorted_longest_compilation_comes_first = dataset?.sort_by {|name_of_the_program, n_seconds|
      n_seconds
    }.reverse
    index = 0
    sorted_longest_compilation_comes_first.each {|name_of_the_program, n_seconds| index += 1
      left_padded  = ("#{name_of_the_program.strip}:").ljust(26)
      right_padded_showing_n_seconds = (
        '%.2f' % n_seconds.to_s.strip.to_f
      ).rjust(12)
      right_padded_showing_n_seconds << "#{rev} seconds"
      n_minutes = (n_seconds.to_f / 60.0).round(2) # Rounding to 2 is better.
      n_minutes = n_minutes.to_s.ljust(4,'0')
      # =================================================================== #
      # Next count the amount of numbers before the '.' point. If there
      # are at the least two numbers, we will .ljust(5,'0') rather than
      # .ljust(4,'0').
      # =================================================================== #
      if n_minutes.include? '.'
        first_splitted = n_minutes.split('.').first
        if first_splitted.size > 1
          n_minutes = n_minutes.to_s.ljust(5,'0')
        end
      end
      # =================================================================== #
      # The program name may be upcased; since we store only downcased
      # variants for the name of the .yml file at hand, we will also
      # .downcase() on the program name in the following code.
      # =================================================================== #
      archive_size = action(
        :fast_return_file_size_of_this_program,
        name_of_the_program.downcase.delete('-') # Downcase it here.
      )
      colourized_file_size = mediumslateblue(
        "#{archive_size.to_s.rjust(10)} Kb"
      )
      result = '  '+
               sfancy(left_padded)+' '+
               simp(right_padded_showing_n_seconds)+' '+
               orange(
                 ( "(#{n_minutes}" ).rjust(6)+' minutes)'
               )
      result << " #{colourized_file_size}"
      result << mediumseagreen(" ##{index}")
      @body << "#{result}\n"
    }
    @body << "\n"
  end
end
try_to_load_up_the_dataset() click to toggle source
#

try_to_load_up_the_dataset

#
# File lib/rbt/actions/individual_actions/statistics/return_compile_time_statistics.rb, line 116
def try_to_load_up_the_dataset
  _ = main_file?
  if File.exist? _
    @dataset = YAML.load_file(_)
  end
end