module SmartName::Parts
naming conventions: methods that end with _name return name objects the same methods without _name return strings
Attributes
part_keys[R]
parts[R]
simple[R]
simple?[R]
to_a[R]
Public Instance Methods
+(other)
click to toggle source
# File lib/smart_name/parts.rb 102 def + other 103 self.class.new(parts + other.to_name.parts) 104 end
[](*args)
click to toggle source
# File lib/smart_name/parts.rb 106 def [] *args 107 self.class.new parts[*args] 108 end
initialize_parts()
click to toggle source
# File lib/smart_name/parts.rb 11 def initialize_parts 12 # -1 = don't suppress trailing null fields 13 @parts = @s.split(/\s*#{JOINT_RE}\s*/, -1) 14 @simple = @parts.size <= 1 15 # simple check needed to avoid inifinite recursion 16 @part_keys = 17 @simple ? [simple_key] : @parts.map { |p| p.to_name.simple_key } 18 end
left()
click to toggle source
# File lib/smart_name/parts.rb 20 def left 21 @left ||= simple? ? nil : parts[0..-2] * self.class.joint 22 end
left_key()
click to toggle source
# File lib/smart_name/parts.rb 36 def left_key 37 @left_key ||= simple? ? nil : part_keys[0..-2] * self.class.joint 38 end
left_name()
click to toggle source
# File lib/smart_name/parts.rb 28 def left_name 29 @left_name ||= left && self.class.new(left) 30 end
parent_keys()
click to toggle source
# File lib/smart_name/parts.rb 52 def parent_keys 53 @parent_keys ||= junction? ? [left_key, right_key] : [] 54 end
parent_names()
click to toggle source
# File lib/smart_name/parts.rb 48 def parent_names 49 @parent_names ||= junction? ? [left_name, right_name] : [] 50 end
parents()
click to toggle source
# File lib/smart_name/parts.rb 44 def parents 45 @parents ||= junction? ? [left, right] : [] 46 end
part_names()
click to toggle source
# File lib/smart_name/parts.rb 75 def part_names 76 @part_names ||= parts.map(&:to_name) 77 end
piece_names()
click to toggle source
# File lib/smart_name/parts.rb 79 def piece_names 80 @piece_names ||= pieces.map(&:to_name) 81 end
pieces()
click to toggle source
self and all ancestors (= parts and recursive lefts) @example
"A+B+C+D".to_name.pieces # => ["A", "B", "C", "D", "A+B", "A+B+C", "A+B+C+D"]
# File lib/smart_name/parts.rb 87 def pieces 88 @pieces ||= 89 if simple? 90 [self] 91 else 92 junction_pieces = [] 93 parts[1..-1].inject parts[0] do |left, right| 94 piece = [left, right] * self.class.joint 95 junction_pieces << piece 96 piece 97 end 98 parts + junction_pieces 99 end 100 end
right()
click to toggle source
# File lib/smart_name/parts.rb 24 def right 25 @right ||= simple? ? nil : parts[-1] 26 end
right_key()
click to toggle source
# File lib/smart_name/parts.rb 40 def right_key 41 @right_key ||= simple? ? nil : part_keys.last 42 end
right_name()
click to toggle source
# File lib/smart_name/parts.rb 32 def right_name 33 @right_name ||= right && self.class.new(right) 34 end
tag()
click to toggle source
# File lib/smart_name/parts.rb 63 def tag 64 @tag ||= simple? ? s : right 65 end
tag_name()
click to toggle source
# File lib/smart_name/parts.rb 71 def tag_name 72 @tag_name ||= simple? ? self : right_name 73 end
trunk()
click to toggle source
Note that all names have a trunk and tag, but only junctions have left and right
# File lib/smart_name/parts.rb 59 def trunk 60 @trunk ||= simple? ? s : left 61 end
trunk_name()
click to toggle source
# File lib/smart_name/parts.rb 67 def trunk_name 68 @trunk_name ||= simple? ? self : left_name 69 end