class UICov::Gentpl

Constants

DEFAULT_FILENAME
OPTIONS
USAGE_INFO

Public Class Methods

new() click to toggle source

or rt#{COMMAND_PREFIX} [options] –puml=DIR

# File lib/uicov/commands/gentpl.rb, line 36
def initialize
  @template_file = DEFAULT_FILENAME
end

Public Instance Methods

do_job(args) click to toggle source
# File lib/uicov/commands/gentpl.rb, line 40
def do_job(args)
  @cd = CovData.new
  model_files = process_args args
  usage 'Missed model file', USAGE_INFO if model_files.empty?
  parse_models model_files
  @cd.set_processing_date
  @cd.type = CoverageDataType::TEMPLATE
  @cd.save(@template_file)
end

Private Instance Methods

parse(model) click to toggle source
# File lib/uicov/commands/gentpl.rb, line 66
def parse(model)
  model_file = File.expand_path model
  File.open(model_file) do |f|
    begin
      current_screen = $default_screen
      curr_screen_data = nil
      while (line = f.readline.chomp)
        case line
          when ModelPatterns.current_screen_start
            name = $~[1] # $~ - is MatchData of the latest regexp match
            current_screen = name
            cur_screen_data = @cd.add_screen name

          when ModelPatterns.current_screen_end
            current_screen = nil

          when ModelPatterns.transition
            name, to = $~[1..2]
            if current_screen.nil?
              Log.error %Q^
                Wrong model: Transition #{name} is done from unknown screen.
                Found in model #{model_file} at line #{f.lineno}
                        ^
            end
            cur_screen_data.add_transition name, to

          when ModelPatterns.action
            name = $~[1]
            if current_screen.nil?
              Log.error %Q^
                Wrong model: Action #{name} is done on unknown screen.
                Found in model #{model_file} at line #{f.lineno}
                        ^
            end
            cur_screen_data.add_action name

          when ModelPatterns.check
            name = $~[1]
            if current_screen.nil?
              Log.error %Q^
                Wrong model: Action #{name} is done on unknown screen.
                Found in model #{model_file} at line #{f.lineno}
                        ^
            end
            cur_screen_data.add_check name

          when ModelPatterns.element
            name = $~[1]
            cur_screen_data.add_element name

          else
            #d line
        end
      end
    rescue EOFError => err
      # it's ok
    end
  end
  @cd.add_input_file model_file, File.mtime(model_file).strftime('%F %R:%S.%3N')
end
parse_models(model_files) click to toggle source
# File lib/uicov/commands/gentpl.rb, line 61
def parse_models(model_files)
  Log.debug "Will parse model files #{model_files}"
  model_files.each { |lf| parse lf }
end
process_args(args) click to toggle source
# File lib/uicov/commands/gentpl.rb, line 52
def process_args(args)
  template_file_option = args.grep(/--template-file=.*/)[0]
  if template_file_option
    @template_file = File.expand_path template_file_option.gsub(/.*=(.+)/, '\1')
    args.delete_if { |e| e == template_file_option }
  end
  return args
end