Class: Kwartz::AttrInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/kwartz/converter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#namesObject (readonly)

Returns the value of attribute names.



114
115
116
# File 'lib/kwartz/converter.rb', line 114

def names
  @names
end

#spacesObject (readonly)

Returns the value of attribute spaces.



114
115
116
# File 'lib/kwartz/converter.rb', line 114

def spaces
  @spaces
end

#valuesObject (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

#eachObject



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

Returns:

  • (Boolean)


150
151
152
# File 'lib/kwartz/converter.rb', line 150

def empty?
  return @names.empty?
end

#has?(name) ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/kwartz/converter.rb', line 117

def has?(name)
  return @values.key?(name)
end