Class: Hiptest::NodeModifiers::ActionwordUniqRenamer
- Inherits:
-
Object
- Object
- Hiptest::NodeModifiers::ActionwordUniqRenamer
- Defined in:
- lib/hiptest-publisher/node_modifiers/actionword_uniq_renamer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #find_uniq_name(name, existing) ⇒ Object
-
#initialize(project) ⇒ ActionwordUniqRenamer
constructor
A new instance of ActionwordUniqRenamer.
- #make_uniq_names ⇒ Object
Constructor Details
#initialize(project) ⇒ ActionwordUniqRenamer
Returns a new instance of ActionwordUniqRenamer.
8 9 10 |
# File 'lib/hiptest-publisher/node_modifiers/actionword_uniq_renamer.rb', line 8 def initialize(project) @project = project end |
Class Method Details
.add(project) ⇒ Object
4 5 6 |
# File 'lib/hiptest-publisher/node_modifiers/actionword_uniq_renamer.rb', line 4 def self.add(project) self.new(project).make_uniq_names end |
Instance Method Details
#find_uniq_name(name, existing) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hiptest-publisher/node_modifiers/actionword_uniq_renamer.rb', line 22 def find_uniq_name(name, existing) return name unless existing.include?(name) index = 1 new_name = "" loop do new_name = "#{name} #{index}" break unless existing.include?(new_name) index += 1 end new_name end |
#make_uniq_names ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/hiptest-publisher/node_modifiers/actionword_uniq_renamer.rb', line 12 def make_uniq_names @project.children[:libraries].children[:libraries].each do |library| library.children[:library_actionwords].each do |library_actionword| existing_names = library.children[:library_actionwords].reject{|aw| aw == library_actionword}.map(&:uniq_name) new_name = find_uniq_name(library_actionword.children[:name], existing_names) library_actionword.uniq_name = new_name end end end |