Module: Duxml::AttrsRule
- Included in:
- AttrsRuleClass
- Defined in:
- lib/duxml/meta/grammar/rule/attrs_rule.rb,
lib/duxml/meta/grammar/rule/attrs_rule.rb
Overview
methods for applying a rule on what attribute names a given Element is allowed to have
Instance Method Summary collapse
-
#applies_to?(change_or_pattern) ⇒ Boolean
Whether this rule does in fact apply.
-
#attr_name ⇒ String
Name of attribute to which this rule applies.
-
#description ⇒ String
Description of self; overrides super to account for cases of missing, required attributes.
-
#pass(change_or_pattern) ⇒ Boolean
True if this rule does not apply to param; false if pattern is for a missing required attribute otherwise returns whether or not any illegal attributes exist.
-
#qualify(change_or_pattern) ⇒ Boolean
Whether or not given pattern passed this test.
-
#relationship ⇒ String
Describes relationship in a word.
-
#required? ⇒ Boolean
Whether or not this attribute is required.
Instance Method Details
#applies_to?(change_or_pattern) ⇒ Boolean
Returns whether this rule does in fact apply.
39 40 41 42 43 44 |
# File 'lib/duxml/meta/grammar/rule/attrs_rule.rb', line 39 def applies_to?(change_or_pattern) return false unless change_or_pattern.respond_to?(:attr_name) return false unless super(change_or_pattern) return false if change_or_pattern.respond_to?(:value) && !change_or_pattern.respond_to?(:time_stamp) statement.include?(change_or_pattern.attr_name.to_s) end |
#attr_name ⇒ String
Returns name of attribute to which this rule applies.
52 53 54 |
# File 'lib/duxml/meta/grammar/rule/attrs_rule.rb', line 52 def attr_name statement.gsub('\b','') end |
#description ⇒ String
Returns description of self; overrides super to account for cases of missing, required attributes.
62 63 64 |
# File 'lib/duxml/meta/grammar/rule/attrs_rule.rb', line 62 def description %(#{relationship.capitalize} Rule that <#{subject}>'s #{relationship} #{required? ? 'must':'can'} include '#{attr_name}') end |
#pass(change_or_pattern) ⇒ Boolean
Returns true if this rule does not apply to param; false if pattern is for a missing required attribute otherwise returns whether or not any illegal attributes exist.
69 70 71 72 73 74 75 76 |
# File 'lib/duxml/meta/grammar/rule/attrs_rule.rb', line 69 def pass(change_or_pattern) if change_or_pattern.respond_to?(:time_stamp) an = change_or_pattern.attr_name.to_s attr_name.include?(an) && !change_or_pattern.abstract? else !change_or_pattern.abstract? end end |
#qualify(change_or_pattern) ⇒ Boolean
Returns whether or not given pattern passed this test.
29 30 31 32 33 34 35 |
# File 'lib/duxml/meta/grammar/rule/attrs_rule.rb', line 29 def qualify(change_or_pattern) @object = change_or_pattern result = pass change_or_pattern super change_or_pattern unless result @object = nil result end |
#relationship ⇒ String
Returns describes relationship in a word.
57 58 59 |
# File 'lib/duxml/meta/grammar/rule/attrs_rule.rb', line 57 def relationship 'attributes' end |
#required? ⇒ Boolean
Returns whether or not this attribute is required.
47 48 49 |
# File 'lib/duxml/meta/grammar/rule/attrs_rule.rb', line 47 def required? requirement == '#REQUIRED' end |