class StringDoc::Attributes
String-based XML attributes.
@api private
Constants
- CLOSING
- OPENING
- SPACING
Attributes
attributes_hash[R]
@api private
Public Class Methods
new(attributes_hash = {})
click to toggle source
# File lib/string_doc/attributes.rb, line 38 def initialize(attributes_hash = {}) @attributes_hash = Hash[attributes_hash.map { |key, value| [key.to_s, value] }] end
Public Instance Methods
==(other)
click to toggle source
# File lib/string_doc/attributes.rb, line 86 def ==(other) other.is_a?(Attributes) && @attributes_hash == other.attributes_hash end
[](key)
click to toggle source
# File lib/string_doc/attributes.rb, line 48 def [](key) @attributes_hash[key.to_s] end
[]=(key, value)
click to toggle source
# File lib/string_doc/attributes.rb, line 44 def []=(key, value) @attributes_hash[key.to_s] = value end
delete(key)
click to toggle source
# File lib/string_doc/attributes.rb, line 52 def delete(key) @attributes_hash.delete(key.to_s) end
each_string() { |""| ... }
click to toggle source
# File lib/string_doc/attributes.rb, line 72 def each_string if @attributes_hash.empty? yield "" else @attributes_hash.each do |name, value| yield SPACING yield name yield OPENING yield value.to_s yield CLOSING end end end
initialize_copy(_)
click to toggle source
@api private
# File lib/string_doc/attributes.rb, line 94 def initialize_copy(_) hash = {} @attributes_hash.each do |key, value| hash[key] = value.dup end @attributes_hash = hash end
key?(key)
click to toggle source
# File lib/string_doc/attributes.rb, line 56 def key?(key) @attributes_hash.key?(key.to_s) end
to_s()
click to toggle source
# File lib/string_doc/attributes.rb, line 60 def to_s string = @attributes_hash.compact.map { |name, value| name + OPENING + value.to_s + CLOSING }.join(SPACING) if string.empty? string else SPACING + string end end
wrap() { |value, key| ... }
click to toggle source
@api private
# File lib/string_doc/attributes.rb, line 104 def wrap @attributes_hash.each do |key, value| @attributes_hash[key] = yield(value, key) end end