Module: Card::Name::FieldsAndTraits
- Included in:
- Card::Name
- Defined in:
- lib/card/name/fields_and_traits.rb
Overview
Name-based “Fields” are compound names in which the right name is treated as an attribute of the left. (Eg MyName+address)
“Traits” are the subset of fields in which the right name corresponds to a card with a codename
Instance Method Summary collapse
- #field(tag_name) ⇒ String
- #field_name(tag) ⇒ Card::Name
- #field_of?(context) ⇒ True/False
-
#field_only? ⇒ True/False
name is relative name containing only the rightmost part.
- #relative_field_name(tag_name) ⇒ Object
Instance Method Details
#field(tag_name) ⇒ String
10 11 12 |
# File 'lib/card/name/fields_and_traits.rb', line 10 def field tag_name field_name(tag_name).s end |
#field_name(tag) ⇒ Card::Name
15 16 17 18 |
# File 'lib/card/name/fields_and_traits.rb', line 15 def field_name tag tag = tag.to_s[1..-1] if !tag.is_a?(Symbol) && tag.to_s[0] == "+" [self, tag].to_name end |
#field_of?(context) ⇒ True/False
21 22 23 24 25 26 27 28 29 |
# File 'lib/card/name/fields_and_traits.rb', line 21 def field_of? context return false unless compound? if context.present? absolute_name(context).left_name.key == context.to_name.key else s.match?(/^\s*\+[^+]+$/) end end |
#field_only? ⇒ True/False
name is relative name containing only the rightmost part
33 34 35 |
# File 'lib/card/name/fields_and_traits.rb', line 33 def field_only? relative? && stripped.to_name.parts.reject(&:blank?).first == parts.last end |
#relative_field_name(tag_name) ⇒ Object
37 38 39 |
# File 'lib/card/name/fields_and_traits.rb', line 37 def relative_field_name tag_name field_name(tag_name).name_from self end |