Module: Reviser::Helpers::Project::Naming
- Included in:
- Components::Organiser
- Defined in:
- lib/reviser/helpers/project.rb
Overview
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).
Constant Summary collapse
- SYMBOLS =
Dictionnary for regex in config file
{ :group => 'GROUP', :firstname => 'FIRSTN', :name => 'NAME', :user => 'USER', :lambda => 'LAMBDA' }
- REGEX =
Regex to associate, depending the used word in Cfg
{ :group => '([A-Za-z0-9]{3,4})', :firstname => '([A-Za-z\-]+)', :name => '([A-Za-z]+)', :user => '([^_]*)', :lambda => '[a-zA-Z0-9 _]*' }
Instance Method Summary collapse
-
#analyze_formatter ⇒ Hash
Get formatter written in the config file and count occurences of each word in the dictionnary SYMBOLS.
- #ask(entry) ⇒ Object
-
#check_entry_name(entry) ⇒ Object
Apply regex of user on the entry name and try to get all interested matched values.
-
#format(entry) ⇒ Object
Analyze et get all informations that could be useful in the name of the directory project.
-
#generate_label(infos) ⇒ String
Generate new name of project.
-
#get_position(regex) ⇒ Object
I'm not pround of this method ...
-
#sort_infos(infos) ⇒ Object
Put all datas found in respective variables (students, groups, teams ...).
Instance Method Details
#analyze_formatter ⇒ Hash
Get formatter written in the config file and count occurences of each word in the dictionnary SYMBOLS.
116 117 118 119 120 121 122 123 124 125 |
# 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) ⇒ Object
244 245 |
# File 'lib/reviser/helpers/project.rb', line 244 def ask entry end |
#check_entry_name(entry) ⇒ Object
Apply regex of user on the entry name and try to get all interested matched values.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# 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) ⇒ Object
Analyze et get all informations that could be useful in the name of the directory project.
133 134 135 136 137 138 139 140 141 |
# 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) ⇒ String
Generate new name of project.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# 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) ⇒ Object
I'm not pround of this method ... associate to a symbol, his position in the regex will give : { 1 => :name, 2 => :firstname }
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# 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) ⇒ Object
Put all datas found in respective variables (students, groups, teams ...).
229 230 231 232 233 234 235 236 237 238 239 240 241 |
# 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 |