module Reviser::Helpers::Project::Naming

This modules is used to scan the name of project in order to get all students who worked. This analysis uses regex of convention given by teachers (config file).

@author Yann Prono

Constants

REGEX

Regex to associate, depending the used word in Cfg

SYMBOLS

Dictionnary for regex in config file

Public Instance Methods

analyze_formatter() click to toggle source

Get formatter written in the config file and count occurences of each word in the dictionnary SYMBOLS. @return [Hash] sym => count.

# File lib/reviser/helpers/project.rb, line 116
def analyze_formatter
        regex = Cfg[:projects_names]
        # Foreach known symbols
        SYMBOLS.each do |k, _|
                # Get numbers of occurences of the word k in regex
                matches = regex.scan(SYMBOLS[k]).size
                # the word K => number of occurences
                @count_patterns[k] = matches if matches > 0
        end
end
ask(entry) click to toggle source
# File lib/reviser/helpers/project.rb, line 244
def ask entry
end
check_entry_name(entry) click to toggle source

Apply regex of user on the entry name and try to get all interested matched values.

# File lib/reviser/helpers/project.rb, line 195
def check_entry_name entry
        regex = Cfg[:projects_names]
        # who work on the current project (entry) ?
        position = get_position regex

        @count_patterns.each do |k, _|
                regex = regex.gsub SYMBOLS[k], REGEX[k]
        end
        
        # Apply created regex
        entry.match Regexp.new(regex)
        pos = 1
        infos = {}

        # Get matched values
        begin
                tmp = eval "$#{pos}"
                if tmp != nil && tmp != ''
                        tmp = tmp.delete '_'
                        infos.has_key?(position[pos]) && infos[position[pos]] << tmp || infos[position[pos]] = [tmp]
                end
                pos += 1
        end while pos <= position.size

        if infos.empty?
                infos[:unknown] = entry
        end
        sort_infos infos
        infos
end
format(entry) click to toggle source

Analyze et get all informations that could be useful in the name of the directory project. @param entry [String] name of directory to analysis.

# File lib/reviser/helpers/project.rb, line 133
   def format entry
           ext = File.extname entry
           entry = File.basename entry, ext

           analyze_formatter if @count_patterns.empty?

group = check_entry_name entry
           generate_label group
   end
generate_label(infos) click to toggle source

Generate new name of project. @param infos [Hash] All informations used for generate a name for the directory. @return [String] the formatted name for directory project

# File lib/reviser/helpers/project.rb, line 148
def generate_label infos
        unless infos.empty?
                label = ''
                infos.reject { |k| k == :group }.each { |_, v|
                        if v.respond_to?('each')
                                v.each { |data|
                                label += data +' '
                        }
                        else
                                label += v + ' '
                        end
                }
                # Inject group of project before name : group/name
                label = infos.key?(:group) && File.join(infos[:group], label) || label
                label
        end
end
get_position(regex) click to toggle source
I'm not pround of this method ...
associate to a symbol, his position in the regex
@example NAME_FIRSTN
will give : {
  1 => :name,
  2 => :firstname

}

# File lib/reviser/helpers/project.rb, line 173
def get_position regex
        res = {}
        SYMBOLS.each do |k,v|
                regex.scan(v) do |_|
                        res[$~.offset(0)[0]] = k
                end
        end

        res = (res.sort_by { |k, _| k }).to_h
        tmp = {}

        index = 1
        res.each do |_,v|
                tmp[index] = v
                index += 1
        end
        tmp
end
sort_infos(infos) click to toggle source

Put all datas found in respective variables (students, groups, teams …). @param infos [Hash] Informations found by regex.

# File lib/reviser/helpers/project.rb, line 229
def sort_infos infos
        if infos.has_key?(:name)
                infos[:name].respond_to?('each') && infos[:name].each { |n| @students << n } || @students << infos[:name] 
                @binoms << infos[:name]
        end
        if infos.has_key?(:group)
                infos[:group] = infos[:group][0].upcase
                sym_group = infos[:group].to_sym
                @projects_per_group[sym_group] = @projects_per_group.key?(sym_group) && @projects_per_group[sym_group] + 1 || 1 
        end
        
        @unknown << infos[:unknown] if infos.key? :unknown
end