Class: Lutaml::Xsd::Validation::XmlAttribute
- Inherits:
-
Object
- Object
- Lutaml::Xsd::Validation::XmlAttribute
- Defined in:
- lib/lutaml/xsd/validation/xml_attribute.rb
Overview
XmlAttribute represents an XML attribute with validation context
This class wraps XML attributes to provide a consistent interface for validation rules. It includes the attribute name, value, and namespace information needed for XSD validation.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace_uri ⇒ Object
readonly
Returns the value of attribute namespace_uri.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare attributes for equality.
-
#hash ⇒ Integer
Generate hash code.
-
#initialize(name, value, namespace_uri = nil, prefix = nil) ⇒ XmlAttribute
constructor
Initialize a new XmlAttribute.
-
#inspect ⇒ String
Detailed string representation.
-
#namespaced? ⇒ Boolean
Check if attribute is in a namespace.
-
#prefixed_name ⇒ String
Get the prefixed name.
-
#qualified_name ⇒ String
Get the qualified name in Clark notation.
-
#to_h ⇒ Hash
Convert to hash representation.
-
#to_s ⇒ String
String representation.
Constructor Details
#initialize(name, value, namespace_uri = nil, prefix = nil) ⇒ XmlAttribute
Initialize a new XmlAttribute
29 30 31 32 33 34 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 29 def initialize(name, value, namespace_uri = nil, prefix = nil) @name = name @value = value @namespace_uri = namespace_uri @prefix = prefix end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 21 def name @name end |
#namespace_uri ⇒ Object (readonly)
Returns the value of attribute namespace_uri.
21 22 23 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 21 def namespace_uri @namespace_uri end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
21 22 23 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 21 def prefix @prefix end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
21 22 23 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 21 def value @value end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare attributes for equality
99 100 101 102 103 104 105 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 99 def ==(other) return false unless other.is_a?(XmlAttribute) @name == other.name && @value == other.value && @namespace_uri == other.namespace_uri end |
#hash ⇒ Integer
Generate hash code
112 113 114 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 112 def hash [@name, @value, @namespace_uri].hash end |
#inspect ⇒ String
Detailed string representation
88 89 90 91 92 93 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 88 def inspect "#<#{self.class.name} " \ "name=#{@name.inspect} " \ "value=#{@value.inspect} " \ "namespace_uri=#{@namespace_uri.inspect}>" end |
#namespaced? ⇒ Boolean
Check if attribute is in a namespace
61 62 63 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 61 def namespaced? !@namespace_uri.nil? && !@namespace_uri.empty? end |
#prefixed_name ⇒ String
Get the prefixed name
50 51 52 53 54 55 56 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 50 def prefixed_name if @prefix && !@prefix.empty? "#{@prefix}:#{@name}" else @name end end |
#qualified_name ⇒ String
Get the qualified name in Clark notation
39 40 41 42 43 44 45 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 39 def qualified_name if @namespace_uri && !@namespace_uri.empty? "{#{@namespace_uri}}#{@name}" else @name end end |
#to_h ⇒ Hash
Convert to hash representation
68 69 70 71 72 73 74 75 76 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 68 def to_h { name: @name, value: @value, namespace_uri: @namespace_uri, prefix: @prefix, qualified_name: qualified_name, }.compact end |
#to_s ⇒ String
String representation
81 82 83 |
# File 'lib/lutaml/xsd/validation/xml_attribute.rb', line 81 def to_s "#{prefixed_name}=\"#{@value}\"" end |