Class: XmlUtils::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/xmlutils/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, normalized = true) ⇒ Attribute

Returns a new instance of Attribute.



304
305
306
307
308
309
# File 'lib/xmlutils/node.rb', line 304

def initialize(name, value, normalized = true)
  @name = name.to_s
  @value = normalized ? value.to_s : normalize(value.to_s)
  @normalized = normalized
  @element = nil
end

Instance Attribute Details

#elementObject

Returns the value of attribute element.



302
303
304
# File 'lib/xmlutils/node.rb', line 302

def element
  @element
end

#nameObject

Returns the value of attribute name.



302
303
304
# File 'lib/xmlutils/node.rb', line 302

def name
  @name
end

#normalizedObject

Returns the value of attribute normalized.



302
303
304
# File 'lib/xmlutils/node.rb', line 302

def normalized
  @normalized
end

#valueObject

Returns the value of attribute value.



302
303
304
# File 'lib/xmlutils/node.rb', line 302

def value
  @value
end

Instance Method Details

#cloneObject



315
316
317
# File 'lib/xmlutils/node.rb', line 315

def clone
  Attribute.new(@name, @value, true)
end

#namespaceObject



327
328
329
330
# File 'lib/xmlutils/node.rb', line 327

def namespace
  prefix = @name.include?(':') ? @name.split(':').first : ''
  prefix == 'xmlns' ? '' : prefix
end

#node_typeObject



311
312
313
# File 'lib/xmlutils/node.rb', line 311

def node_type
  :attribute
end

#prefixObject



332
333
334
# File 'lib/xmlutils/node.rb', line 332

def prefix
  @name.include?(':') ? @name.split(':').first : ''
end

#to_sObject



319
320
321
# File 'lib/xmlutils/node.rb', line 319

def to_s
  @value
end

#to_stringObject



323
324
325
# File 'lib/xmlutils/node.rb', line 323

def to_string
  "#{@name}=\"#{escape(@value)}\""
end