Module: Cardname::Parts

Included in:
Cardname
Defined in:
cardname/lib/cardname/parts.rb

Overview

naming conventions: methods that end with _name return name objects the same methods without _name return strings

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#part_keysObject (readonly)

Returns the value of attribute part_keys.



6
7
8
# File 'cardname/lib/cardname/parts.rb', line 6

def part_keys
  @part_keys
end

#partsObject (readonly)

Returns the value of attribute parts.



6
7
8
# File 'cardname/lib/cardname/parts.rb', line 6

def parts
  @parts
end

#simpleObject (readonly)

Returns the value of attribute simple.



6
7
8
# File 'cardname/lib/cardname/parts.rb', line 6

def simple
  @simple
end

Instance Method Details

#[](*args) ⇒ Object

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



88
89
90
# File 'cardname/lib/cardname/parts.rb', line 88

def [] *args
  self.class.new parts[*args]
end

#ancestorsObject



80
81
82
# File 'cardname/lib/cardname/parts.rb', line 80

def ancestors
  @ancestors ||= pieces.reject { |p| p == self }
end

#leftObject



17
18
19
# File 'cardname/lib/cardname/parts.rb', line 17

def left
  @left ||= simple? ? nil : parts[0..-2] * self.class.joint
end

#left_keyObject



33
34
35
# File 'cardname/lib/cardname/parts.rb', line 33

def left_key
  @left_key ||=  simple? ? nil : part_keys[0..-2] * self.class.joint
end

#left_nameObject



25
26
27
# File 'cardname/lib/cardname/parts.rb', line 25

def left_name
  @left_name ||= left && self.class.new(left)
end

#parent_keysObject



49
50
51
# File 'cardname/lib/cardname/parts.rb', line 49

def parent_keys
  @parent_keys ||= compound? ? [left_key, right_key] : []
end

#parent_namesObject



45
46
47
# File 'cardname/lib/cardname/parts.rb', line 45

def parent_names
  @parent_names ||= compound? ? [left_name, right_name] : []
end

#parentsObject



41
42
43
# File 'cardname/lib/cardname/parts.rb', line 41

def parents
  @parents ||= compound? ? [left, right] : []
end

#part_namesObject



72
73
74
# File 'cardname/lib/cardname/parts.rb', line 72

def part_names
  @part_names ||= parts.map(&:to_name)
end

#piece_namesObject



76
77
78
# File 'cardname/lib/cardname/parts.rb', line 76

def piece_names
  @piece_names ||= pieces.map(&:to_name)
end

#rightObject



21
22
23
# File 'cardname/lib/cardname/parts.rb', line 21

def right
  @right ||= simple? ? nil : parts[-1]
end

#right_keyObject



37
38
39
# File 'cardname/lib/cardname/parts.rb', line 37

def right_key
  @right_key ||= simple? ? nil : part_keys.last
end

#right_nameObject



29
30
31
# File 'cardname/lib/cardname/parts.rb', line 29

def right_name
  @right_name ||= right && self.class.new(right)
end

#tagObject



60
61
62
# File 'cardname/lib/cardname/parts.rb', line 60

def tag
  @tag ||= simple? ? s : right
end

#tag_nameObject



68
69
70
# File 'cardname/lib/cardname/parts.rb', line 68

def tag_name
  @tag_name ||= simple? ? self : right_name
end

#to_aObject

Returns the value of attribute parts.



7
8
9
# File 'cardname/lib/cardname/parts.rb', line 7

def parts
  @parts
end

#trunkObject

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



56
57
58
# File 'cardname/lib/cardname/parts.rb', line 56

def trunk
  @trunk ||= simple? ? s : left
end

#trunk_nameObject



64
65
66
# File 'cardname/lib/cardname/parts.rb', line 64

def trunk_name
  @trunk_name ||= simple? ? self : left_name
end