lib/diachronr/rule.rb in diachronr-1.0.0 vs lib/diachronr/rule.rb in diachronr-1.1.0

- old
+ new

@@ -22,26 +22,28 @@ def categories?(value, categories) !get_categories(value, categories).empty? end def get_categories(value, categories) - categories.select { |c| value.include? c.sign } + categories.select { |c| value && value.include?(c.sign) } end def new_to(categories, category_index, index) t = get_categories(to, categories)[category_index] return to if t.nil? - t.contents[index] + contents = t.contents.chars.include?(',') ? t.contents.split(',') : t.contents.chars + contents[index] end # new_to def new_from(category, char) from.gsub category.sign, char end def category_rules(categories) rules = [] get_categories(from, categories).each_with_index do |cat, i| - cat.contents.each_char.with_index do |f, fi| + contents = cat.contents.chars.include?(',') ? cat.contents.split(',') : cat.contents.chars + contents.each.with_index do |f, fi| rules << Rule.new( "#{new_from(cat, f)}/#{new_to(categories, i, fi)}/#{condition}" ) end end