Class: Card::Name
- Inherits:
-
SmartName
- Object
- SmartName
- Card::Name
- 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/
Class Method Summary collapse
Instance Method Summary collapse
- #absolute? ⇒ Boolean
- #absolute_name(context_name) ⇒ Object
- #child_of?(context_name) ⇒ Boolean
- #code ⇒ Object
- #field(tag_name) ⇒ Object
-
#field_name(tag_name) ⇒ Object
returns full name for a field.
- #field_of?(context_name) ⇒ Boolean
- #relative? ⇒ Boolean
- #relative_field_name(tag_name) ⇒ Object
- #relative_name(context_name) ⇒ Object
- #rstar? ⇒ Boolean
- #set? ⇒ Boolean
- #setting? ⇒ Boolean
- #star? ⇒ Boolean
- #starts_with_joint? ⇒ Boolean
- #stripped ⇒ Object
- #to_sym ⇒ Object
- #trait(tag_code) ⇒ Object
- #trait_name(tag_code) ⇒ Object
- #trait_name?(*traitlist) ⇒ Boolean
Class Method Details
.cardish(mark) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/card/name.rb', line 15 def cardish mark case mark when Card then mark.cardname when Symbol, Integer then Card.quick_fetch(mark).cardname else mark.to_name end end |
.url_key_to_standard(key) ⇒ Object
23 24 25 |
# File 'lib/card/name.rb', line 23 def url_key_to_standard key key.to_s.tr "_", " " end |
Instance Method Details
#absolute? ⇒ Boolean
122 123 124 |
# File 'lib/card/name.rb', line 122 def absolute? !relative? end |
#absolute_name(context_name) ⇒ Object
88 89 90 |
# File 'lib/card/name.rb', line 88 def absolute_name context_name to_absolute_name(context_name) end |
#child_of?(context_name) ⇒ Boolean
92 93 94 95 96 97 98 99 100 |
# File 'lib/card/name.rb', line 92 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 |
#code ⇒ Object
65 66 67 |
# File 'lib/card/name.rb', line 65 def code Card::Codename[Card.fetch_id self] end |
#field(tag_name) ⇒ Object
61 62 63 |
# File 'lib/card/name.rb', line 61 def field tag_name field_name(tag_name).s end |
#field_name(tag_name) ⇒ Object
returns full name for a field
70 71 72 73 74 75 76 77 78 |
# File 'lib/card/name.rb', line 70 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
102 103 104 105 106 107 108 |
# File 'lib/card/name.rb', line 102 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
118 119 120 |
# File 'lib/card/name.rb', line 118 def relative? s =~ RELATIVE_REGEXP || starts_with_joint? end |
#relative_field_name(tag_name) ⇒ Object
80 81 82 |
# File 'lib/card/name.rb', line 80 def relative_field_name tag_name field_name(tag_name).relative_name(self) end |
#relative_name(context_name) ⇒ Object
84 85 86 |
# File 'lib/card/name.rb', line 84 def relative_name context_name to_show(*context_name.to_name.parts).to_name end |
#rstar? ⇒ Boolean
32 33 34 |
# File 'lib/card/name.rb', line 32 def rstar? right && "*" == right[0, 1] end |
#set? ⇒ Boolean
114 115 116 |
# File 'lib/card/name.rb', line 114 def set? Set::Pattern.card_keys[tag_name.key] end |
#setting? ⇒ Boolean
110 111 112 |
# File 'lib/card/name.rb', line 110 def setting? Set::Type::Setting.member_names[key] end |
#star? ⇒ Boolean
28 29 30 |
# File 'lib/card/name.rb', line 28 def star? simple? && "*" == s[0, 1] end |
#starts_with_joint? ⇒ Boolean
130 131 132 |
# File 'lib/card/name.rb', line 130 def starts_with_joint? s =~ /^\+/ end |
#stripped ⇒ Object
126 127 128 |
# File 'lib/card/name.rb', line 126 def stripped s.gsub RELATIVE_REGEXP, "" end |
#to_sym ⇒ Object
134 135 136 |
# File 'lib/card/name.rb', line 134 def to_sym s.to_sym end |
#trait(tag_code) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/card/name.rb', line 53 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
47 48 49 50 51 |
# File 'lib/card/name.rb', line 47 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
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/card/name.rb', line 36 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 |