class Ayril::XMLElement::XMLCSSHash

Public Class Methods

new(element) click to toggle source
# File lib/ayril/xml_element/xml_css_hash.rb, line 4
def initialize(element)
  if not (@element = element).has_attribute? "style"
    @element.write_attribute "style", ''
  end
  css = @element.read_attribute "style"
  css.gsub(/\n/, '').split(';').invoke(:strip).compact.each do |property|
    property.split(':').tap { |p| self[p.shift] = p.join(':').strip }
  end.tap { sync }
end

Public Instance Methods

+(h)
Alias for: merge!
-(k)
Alias for: delete
[](k)
Alias for: fetch
[]=(k, v)
Alias for: store
clear() click to toggle source
Calls superclass method
# File lib/ayril/xml_element/xml_css_hash.rb, line 31
def clear; super.tap { sync } end
delete(k) click to toggle source
Calls superclass method
# File lib/ayril/xml_element/xml_css_hash.rb, line 25
def delete(k) super(k).tap { sync } end
Also aliased as: -
delete_if(&blk) click to toggle source
Calls superclass method
# File lib/ayril/xml_element/xml_css_hash.rb, line 28
def delete_if(&blk) super(&blk).tap { sync } end
fetch(k) click to toggle source
Calls superclass method
# File lib/ayril/xml_element/xml_css_hash.rb, line 22
def fetch(k) super(k).tap { sync } end
Also aliased as: []
inspect() click to toggle source
# File lib/ayril/xml_element/xml_css_hash.rb, line 17
def inspect; "#<#{self.class} {#{self.to_css}}>" end
merge!(h) click to toggle source
Calls superclass method
# File lib/ayril/xml_element/xml_css_hash.rb, line 33
def merge!(h) super(h).tap { sync } end
Also aliased as: update!, +
reject!(&blk) click to toggle source
Calls superclass method
# File lib/ayril/xml_element/xml_css_hash.rb, line 29
def reject!(&blk) super(&blk).tap { sync } end
replace(h) click to toggle source
Calls superclass method
# File lib/ayril/xml_element/xml_css_hash.rb, line 30
def replace(h) super(h).tap { sync } end
store(k, v) click to toggle source
Calls superclass method
# File lib/ayril/xml_element/xml_css_hash.rb, line 19
def store(k, v) super(k, v).tap { sync } end
Also aliased as: []=
sync() click to toggle source
# File lib/ayril/xml_element/xml_css_hash.rb, line 37
def sync
  @element.removeAttributeForName("style") and return if self.size == 0
  @element.write_attribute "style", self.to_css
end
to_css() click to toggle source
# File lib/ayril/xml_element/xml_css_hash.rb, line 14
def to_css; self.map { |k, v| "#{k}: #{v}" }.join "; " end
Also aliased as: to_s
to_s()
Alias for: to_css
update!(h)
Alias for: merge!