Module: Cardname::Fields
- Included in:
- Cardname
- Defined in:
- cardname/lib/cardname/fields.rb
Overview
Name-based “Fields” are compound names in which the right name is treated as an attribute of the left. (Eg MyName+address is a field of MyName)
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
6 7 8 |
# File 'cardname/lib/cardname/fields.rb', line 6 def field tag_name field_name(tag_name).s end |
#field_name(tag) ⇒ Card::Name
11 12 13 14 |
# File 'cardname/lib/cardname/fields.rb', line 11 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
17 18 19 20 21 22 23 24 25 |
# File 'cardname/lib/cardname/fields.rb', line 17 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
29 30 31 |
# File 'cardname/lib/cardname/fields.rb', line 29 def field_only? relative? && stripped.to_name.parts.reject(&:blank?).first == parts.last end |
#relative_field_name(tag_name) ⇒ Object
33 34 35 |
# File 'cardname/lib/cardname/fields.rb', line 33 def relative_field_name tag_name field_name(tag_name).name_from self end |