Class: Ayril::XMLElement::XMLCSSHash
- Defined in:
- lib/ayril/xml_element/xml_css_hash.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(k) ⇒ Object (also: #-)
- #delete_if(&blk) ⇒ Object
- #fetch(k) ⇒ Object (also: #[])
-
#initialize(element) ⇒ XMLCSSHash
constructor
A new instance of XMLCSSHash.
- #inspect ⇒ Object
- #merge!(h) ⇒ Object (also: #update!, #+)
- #reject!(&blk) ⇒ Object
- #replace(h) ⇒ Object
- #store(k, v) ⇒ Object (also: #[]=)
- #sync ⇒ Object
- #to_css ⇒ Object (also: #to_s)
Constructor Details
#initialize(element) ⇒ XMLCSSHash
Returns a new instance of XMLCSSHash.
4 5 6 7 8 9 10 11 12 |
# 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 |
Instance Method Details
#clear ⇒ Object
31 |
# File 'lib/ayril/xml_element/xml_css_hash.rb', line 31 def clear; super.tap { sync } end |
#delete(k) ⇒ Object Also known as: -
25 |
# File 'lib/ayril/xml_element/xml_css_hash.rb', line 25 def delete(k) super(k).tap { sync } end |
#delete_if(&blk) ⇒ Object
28 |
# File 'lib/ayril/xml_element/xml_css_hash.rb', line 28 def delete_if(&blk) super(&blk).tap { sync } end |
#fetch(k) ⇒ Object Also known as: []
22 |
# File 'lib/ayril/xml_element/xml_css_hash.rb', line 22 def fetch(k) super(k).tap { sync } end |
#inspect ⇒ Object
17 |
# File 'lib/ayril/xml_element/xml_css_hash.rb', line 17 def inspect; "#<#{self.class} {#{self.to_css}}>" end |
#merge!(h) ⇒ Object Also known as: update!, +
33 |
# File 'lib/ayril/xml_element/xml_css_hash.rb', line 33 def merge!(h) super(h).tap { sync } end |
#reject!(&blk) ⇒ Object
29 |
# File 'lib/ayril/xml_element/xml_css_hash.rb', line 29 def reject!(&blk) super(&blk).tap { sync } end |
#replace(h) ⇒ Object
30 |
# File 'lib/ayril/xml_element/xml_css_hash.rb', line 30 def replace(h) super(h).tap { sync } end |
#store(k, v) ⇒ Object Also known as: []=
19 |
# File 'lib/ayril/xml_element/xml_css_hash.rb', line 19 def store(k, v) super(k, v).tap { sync } end |
#sync ⇒ Object
37 38 39 40 |
# 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 ⇒ Object Also known as: to_s
14 |
# File 'lib/ayril/xml_element/xml_css_hash.rb', line 14 def to_css; self.map { |k, v| "#{k}: #{v}" }.join "; " end |