module Cardname::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]
to_a[R]

Public Instance Methods

[](*args) click to toggle source

def + other

self.class.new(parts + other.to_name.parts)

end

# File lib/cardname/parts.rb, line 88
def [] *args
  self.class.new parts[*args]
end
ancestors() click to toggle source
# File lib/cardname/parts.rb, line 80
def ancestors
  @ancestors ||= pieces.reject { |p| p == self }
end
left() click to toggle source
# File lib/cardname/parts.rb, line 17
def left
  @left ||= simple? ? nil : parts[0..-2] * self.class.joint
end
left_key() click to toggle source
# File lib/cardname/parts.rb, line 33
def left_key
  @left_key ||=  simple? ? nil : part_keys[0..-2] * self.class.joint
end
left_name() click to toggle source
# File lib/cardname/parts.rb, line 25
def left_name
  @left_name ||= left && self.class.new(left)
end
parent_keys() click to toggle source
# File lib/cardname/parts.rb, line 49
def parent_keys
  @parent_keys ||= compound? ? [left_key, right_key] : []
end
parent_names() click to toggle source
# File lib/cardname/parts.rb, line 45
def parent_names
  @parent_names ||= compound? ? [left_name, right_name] : []
end
parents() click to toggle source
# File lib/cardname/parts.rb, line 41
def parents
  @parents ||= compound? ? [left, right] : []
end
part_names() click to toggle source
# File lib/cardname/parts.rb, line 72
def part_names
  @part_names ||= parts.map(&:to_name)
end
piece_names() click to toggle source
# File lib/cardname/parts.rb, line 76
def piece_names
  @piece_names ||= pieces.map(&:to_name)
end
right() click to toggle source
# File lib/cardname/parts.rb, line 21
def right
  @right ||= simple? ? nil : parts[-1]
end
right_key() click to toggle source
# File lib/cardname/parts.rb, line 37
def right_key
  @right_key ||= simple? ? nil : part_keys.last
end
right_name() click to toggle source
# File lib/cardname/parts.rb, line 29
def right_name
  @right_name ||= right && self.class.new(right)
end
tag() click to toggle source
# File lib/cardname/parts.rb, line 60
def tag
  @tag ||= simple? ? s : right
end
tag_name() click to toggle source
# File lib/cardname/parts.rb, line 68
def tag_name
  @tag_name ||= simple? ? self : right_name
end
trunk() click to toggle source

Note that all names have a trunk and tag, but only junctions have left and right

# File lib/cardname/parts.rb, line 56
def trunk
  @trunk ||= simple? ? s : left
end
trunk_name() click to toggle source
# File lib/cardname/parts.rb, line 64
def trunk_name
  @trunk_name ||= simple? ? self : left_name
end