Class: Kwartz::AttrInfo
- Inherits:
-
Object
- Object
- Kwartz::AttrInfo
- Defined in:
- lib/kwartz/converter.rb
Instance Attribute Summary collapse
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#spaces ⇒ Object
readonly
Returns the value of attribute spaces.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #delete(name) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #has?(name) ⇒ Boolean
-
#initialize(attr_str) ⇒ AttrInfo
constructor
A new instance of AttrInfo.
Constructor Details
#initialize(attr_str) ⇒ AttrInfo
Returns a new instance of AttrInfo.
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/kwartz/converter.rb', line 104 def initialize(attr_str) @names = [] @values = {} @spaces = {} attr_str.scan(/(\s+)([-:_\w]+)="([^"]*?)"/) do |space, name, value| @names << name unless @values.key?(name) @values[name] = value @spaces[name] = space end end |
Instance Attribute Details
#names ⇒ Object (readonly)
Returns the value of attribute names.
114 115 116 |
# File 'lib/kwartz/converter.rb', line 114 def names @names end |
#spaces ⇒ Object (readonly)
Returns the value of attribute spaces.
114 115 116 |
# File 'lib/kwartz/converter.rb', line 114 def spaces @spaces end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
114 115 116 |
# File 'lib/kwartz/converter.rb', line 114 def values @values end |
Instance Method Details
#[](name) ⇒ Object
122 123 124 |
# File 'lib/kwartz/converter.rb', line 122 def [](name) return @values[name] end |
#[]=(name, value) ⇒ Object
127 128 129 130 131 |
# File 'lib/kwartz/converter.rb', line 127 def []=(name, value) @names << name unless has?(name) @values[name] = value @spaces[name] = ' ' unless @spaces.key?(name) end |
#delete(name) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/kwartz/converter.rb', line 141 def delete(name) if has?(name) @names.delete(name) @values.delete(name) @spaces.delete(name) end end |
#each ⇒ Object
134 135 136 137 138 |
# File 'lib/kwartz/converter.rb', line 134 def each @names.each do |name| yield(@spaces[name], name, @values[name]) end end |
#empty? ⇒ Boolean
150 151 152 |
# File 'lib/kwartz/converter.rb', line 150 def empty? return @names.empty? end |
#has?(name) ⇒ Boolean
117 118 119 |
# File 'lib/kwartz/converter.rb', line 117 def has?(name) return @values.key?(name) end |