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

Instance Method Details

#applies_to?(change_or_pattern) ⇒ Boolean

Returns whether this rule does in fact apply.

Parameters:

Returns:

  • (Boolean)

    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_nameString

Returns name of attribute to which this rule applies.

Returns:

  • (String)

    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

#descriptionString

Returns description of self; overrides super to account for cases of missing, required attributes.

Returns:

  • (String)

    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.

Parameters:

Returns:

  • (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



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.

Parameters:

  • change_or_pattern (Duxml::Pattern)

    checks an doc of type change_or_pattern.subject against change_or_pattern

Returns:

  • (Boolean)

    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

#relationshipString

Returns describes relationship in a word.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    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