module Cardname::Manipulate
Public Instance Methods
num_parts()
click to toggle source
# File lib/cardname/manipulate.rb, line 37 def num_parts parts.length end
prepend_joint()
click to toggle source
# File lib/cardname/manipulate.rb, line 41 def prepend_joint joint = self.class.joint self =~ /^#{Regexp.escape joint}/ ? self : (joint + self) end
sub_in(str, with: %i[capitalize downcase].product(%i[pluralize singularize]) .inject(str) do |s, (m1, m2)| s.gsub(/\b
click to toggle source
# File lib/cardname/manipulate.rb, line 46 def sub_in str, with: %i[capitalize downcase].product(%i[pluralize singularize]) .inject(str) do |s, (m1, m2)| s.gsub(/\b#{send(m1).send(m2)}\b/, with.send(m1).send(m2)) end
swap(old, new)
click to toggle source
swap a subname keys are used for comparison
# File lib/cardname/manipulate.rb, line 5 def swap old, new old_name = old.to_name new_name = new.to_name return self if old_name.num_parts > num_parts return swap_part(old_name, new_name) if old_name.simple? return self unless include? old_name swap_all_subsequences(old_name, new_name).to_name end
swap_part(oldpart, newpart)
click to toggle source
# File lib/cardname/manipulate.rb, line 15 def swap_part oldpart, newpart ensure_simpleness oldpart, "Use 'swap' to swap junctions" oldpart = oldpart.to_name newpart = newpart.to_name parts.map do |p| oldpart == p ? newpart : p end.to_name end
swap_piece(oldpiece, newpiece)
click to toggle source
# File lib/cardname/manipulate.rb, line 26 def swap_piece oldpiece, newpiece oldpiece = oldpiece.to_name newpiece = newpiece.to_name return swap_part oldpiece, newpiece if oldpiece.simple? return self unless starts_with_parts?(oldpiece) return newpiece if oldpiece.num_parts == num_parts self.class.new [newpiece, self[oldpiece.num_parts..-1]].flatten end