Class: StringDoc::Attributes Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_hashObject (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

#eachObject

Yields each attribute.



36
# File 'lib/string_doc/attributes.rb', line 36

def_delegators :@attributes_hash, :keys, :each

#each_stringObject

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.

Returns:

  • (Boolean)


36
# File 'lib/string_doc/attributes.rb', line 36

def_delegators :@attributes_hash, :keys, :each

#keysObject

Returns the attribute keys.



36
# File 'lib/string_doc/attributes.rb', line 36

def_delegators :@attributes_hash, :keys, :each

#to_sObject

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

#wrapObject

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