Class: SvgConform::Requirements::ElementRequirementConfig
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- SvgConform::Requirements::ElementRequirementConfig
- Defined in:
- lib/svg_conform/requirements/element_requirement_config.rb
Overview
Represents an allowed SVG element configuration with its allowed attributes
Instance Method Summary collapse
-
#allowed_attributes ⇒ Object
Get list of allowed attributes (those not prefixed with !).
-
#attribute_allowed?(attr_name) ⇒ Boolean
Check if an attribute is allowed for this element.
-
#disallowed_attributes ⇒ Object
Get list of explicitly disallowed attributes (those prefixed with !).
-
#global_config? ⇒ Boolean
Check if this is a global config (applies to all elements).
- #to_s ⇒ Object
Instance Method Details
#allowed_attributes ⇒ Object
Get list of allowed attributes (those not prefixed with !)
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/svg_conform/requirements/element_requirement_config.rb', line 53 def allowed_attributes return [] unless attr allowed = attr.filter_map do |attribute| attribute.downcase unless attribute.start_with?("!") end # Add common attributes common_attrs = %w[id class style xmlns] (allowed + common_attrs).uniq end |
#attribute_allowed?(attr_name) ⇒ Boolean
Check if an attribute is allowed for this element
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/svg_conform/requirements/element_requirement_config.rb', line 20 def attribute_allowed?(attr_name) return false unless attr attr_name = attr_name.downcase # Common attributes that are allowed on all elements common_attrs = %w[id class style xmlns] return true if common_attrs.include?(attr_name) # Skip xmlns: and xml: prefixed attributes return true if attr_name.start_with?("xmlns:", "xml:") # Check if explicitly disallowed (prefixed with !) return false if attr.any? do |attribute| attribute.start_with?("!") && attribute[1..].downcase == attr_name end # Check if in allowed list attr.any? do |attribute| !attribute.start_with?("!") && attribute.downcase == attr_name end end |
#disallowed_attributes ⇒ Object
Get list of explicitly disallowed attributes (those prefixed with !)
44 45 46 47 48 49 50 |
# File 'lib/svg_conform/requirements/element_requirement_config.rb', line 44 def disallowed_attributes return [] unless attr attr.filter_map do |attribute| attribute[1..].downcase if attribute.start_with?("!") end end |
#global_config? ⇒ Boolean
Check if this is a global config (applies to all elements)
66 67 68 |
# File 'lib/svg_conform/requirements/element_requirement_config.rb', line 66 def global_config? tag == "*" end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/svg_conform/requirements/element_requirement_config.rb', line 70 def to_s "ElementRequirementConfig(#{tag}: #{attr&.join(', ') || 'none'})" end |