Class: Card::Name

Inherits:
SmartName
  • Object
show all
Defined in:
lib/card/name.rb,
lib/card/name/view_name.rb

Defined Under Namespace

Classes: ViewName

Constant Summary collapse

RELATIVE_REGEXP =
/\b_(left|right|whole|self|user|main|\d+|L*R?)\b/

Instance Method Summary collapse

Instance Method Details

#absolute?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/card/name.rb', line 108

def absolute?
  !relative?
end

#absolute_name(context_name) ⇒ Object



74
75
76
# File 'lib/card/name.rb', line 74

def absolute_name context_name
  to_absolute_name(context_name)
end

#child_of?(context_name) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
86
# File 'lib/card/name.rb', line 78

def child_of? context_name
  if context_name.present?
    # Do I still equal myself after I've been relativised in the context
    # of context_name?
    relative_name(context_name).key != absolute_name(context_name).key
  else
    s.match(/^\s*\+/)
  end
end

#codeObject



51
52
53
# File 'lib/card/name.rb', line 51

def code
  Card::Codename[Card.fetch_id self]
end

#field(tag_name) ⇒ Object



47
48
49
# File 'lib/card/name.rb', line 47

def field tag_name
  field_name(tag_name).s
end

#field_name(tag_name) ⇒ Object

returns full name for a field



56
57
58
59
60
61
62
63
64
# File 'lib/card/name.rb', line 56

def field_name tag_name
  case tag_name
  when Symbol
    trait_name tag_name
  else
    tag_name = tag_name.to_s[1..-1] if tag_name.to_s[0] == "+"
    [self, tag_name].to_name
  end
end

#field_of?(context_name) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
91
92
93
94
# File 'lib/card/name.rb', line 88

def field_of? context_name
  if context_name.present?
    child_of?(context_name) && relative_name(context_name).length == 2
  else
    s.match(/^\s*\+[^+]+$/)
  end
end

#relative?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/card/name.rb', line 104

def relative?
  s =~ RELATIVE_REGEXP || starts_with_joint?
end

#relative_field_name(tag_name) ⇒ Object



66
67
68
# File 'lib/card/name.rb', line 66

def relative_field_name tag_name
  field_name(tag_name).relative_name(self)
end

#relative_name(context_name) ⇒ Object



70
71
72
# File 'lib/card/name.rb', line 70

def relative_name context_name
  to_show(*context_name.to_name.parts).to_name
end

#rstar?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/card/name.rb', line 18

def rstar?
  right && "*" == right[0, 1]
end

#set?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/card/name.rb', line 100

def set?
  Set::Pattern.card_keys[tag_name.key]
end

#setting?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/card/name.rb', line 96

def setting?
  Set::Type::Setting.member_names[key]
end

#star?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/card/name.rb', line 14

def star?
  simple? && "*" == s[0, 1]
end

#starts_with_joint?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/card/name.rb', line 116

def starts_with_joint?
  s =~ /^\+/
end

#strippedObject



112
113
114
# File 'lib/card/name.rb', line 112

def stripped
  s.gsub RELATIVE_REGEXP, ""
end

#to_symObject



120
121
122
# File 'lib/card/name.rb', line 120

def to_sym
  s.to_sym
end

#trait(tag_code) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/card/name.rb', line 39

def trait tag_code
  if (name = trait_name tag_code)
    name.s
  else
    raise Card::Error::NotFound, "unknown codename: #{tag_code}"
  end
end

#trait_name(tag_code) ⇒ Object



33
34
35
36
37
# File 'lib/card/name.rb', line 33

def trait_name tag_code
  (card_id = Card::Codename[tag_code]) &&
    (card = Card.quick_fetch card_id) &&
    [self, card.cardname].to_name
end

#trait_name?(*traitlist) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
# File 'lib/card/name.rb', line 22

def trait_name? *traitlist
  junction? && begin
    right_key = right_name.key
    traitlist.find do |codename|
      (card_id = Card::Codename[codename]) &&
        (card = Card.quick_fetch card_id) &&
        card.key == right_key
    end.present?
  end
end