Class: StringDoc::Attributes Private
- Inherits:
-
Object
- Object
- StringDoc::Attributes
- Extended by:
- Forwardable
- Includes:
- Pakyow::Support::SafeStringHelpers
- Defined in:
- lib/string_doc/attributes.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
String-based XML attributes.
Constant Summary collapse
- OPENING =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'="'
- CLOSING =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'"'
- SPACING =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
" "
Instance Attribute Summary collapse
- #attributes_hash ⇒ Object readonly private
Instance Method Summary collapse
- #==(other) ⇒ Object private
-
#[](key) ⇒ Object
private
Looks up a value for an attribute.
-
#[]=(key, value) ⇒ Object
private
Sets a value for an attribute.
-
#delete(key) ⇒ Object
private
Removes an attribute by name.
-
#each ⇒ Object
Yields each attribute.
- #each_string ⇒ Object private
-
#initialize(attributes_hash = {}) ⇒ Attributes
constructor
private
A new instance of Attributes.
- #initialize_copy(_) ⇒ Object private
-
#key?(key) ⇒ Boolean
private
Returns true if value is a key.
-
#keys ⇒ Object
Returns the attribute keys.
- #to_s ⇒ Object private
- #wrap ⇒ Object private
Constructor Details
#initialize(attributes_hash = {}) ⇒ Attributes
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Attributes.
38 39 40 41 42 |
# 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 |
Instance Attribute Details
#attributes_hash ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 |
# File 'lib/string_doc/attributes.rb', line 91 def attributes_hash @attributes_hash end |
Instance Method Details
#==(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 |
# File 'lib/string_doc/attributes.rb', line 86 def ==(other) other.is_a?(Attributes) && @attributes_hash == other.attributes_hash end |
#[](key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Looks up a value for an attribute.
36 |
# File 'lib/string_doc/attributes.rb', line 36 def_delegators :@attributes_hash, :keys, :each |
#[]=(key, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets a value for an attribute.
36 |
# File 'lib/string_doc/attributes.rb', line 36 def_delegators :@attributes_hash, :keys, :each |
#delete(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes an attribute by name.
36 |
# File 'lib/string_doc/attributes.rb', line 36 def_delegators :@attributes_hash, :keys, :each |
#each ⇒ Object
Yields each attribute.
36 |
# File 'lib/string_doc/attributes.rb', line 36 def_delegators :@attributes_hash, :keys, :each |
#each_string ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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(_) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
94 95 96 97 98 99 100 101 |
# 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) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if value is a key.
36 |
# File 'lib/string_doc/attributes.rb', line 36 def_delegators :@attributes_hash, :keys, :each |
#keys ⇒ Object
Returns the attribute keys.
36 |
# File 'lib/string_doc/attributes.rb', line 36 def_delegators :@attributes_hash, :keys, :each |
#to_s ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 64 65 66 67 68 69 70 |
# 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 ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
104 105 106 107 108 |
# File 'lib/string_doc/attributes.rb', line 104 def wrap @attributes_hash.each do |key, value| @attributes_hash[key] = yield(value, key) end end |