Class: Hpricot::Styles
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(k, v) ⇒ Object
- #delete(key) ⇒ Object
- #empty? ⇒ Boolean
- #has_style?(key) ⇒ Boolean
-
#initialize(e) ⇒ Styles
constructor
A new instance of Styles.
- #properties ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(e) ⇒ Styles
Returns a new instance of Styles.
23 24 25 |
# File 'lib/hpricot_ext.rb', line 23 def initialize e @element = e end |
Instance Method Details
#[](key) ⇒ Object
34 35 36 |
# File 'lib/hpricot_ext.rb', line 34 def [] key properties[key] end |
#[]=(k, v) ⇒ Object
38 39 40 41 |
# File 'lib/hpricot_ext.rb', line 38 def []= k, v s = properties.map {|pty,val| "#{pty}:#{val}"}.join(";") @element.set_attribute("style", "#{s.chomp(";")};#{k}:#{v}".sub(/^\;/, "")) end |
#delete(key) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/hpricot_ext.rb', line 27 def delete(key) p = properties.dup if p.delete key @element.set_attribute("style", "#{p.map {|pty,val| "#{pty}:#{val}"}.join(";")}") end end |
#empty? ⇒ Boolean
43 44 45 |
# File 'lib/hpricot_ext.rb', line 43 def empty? return true if properties.size == 0 end |
#has_style?(key) ⇒ Boolean
47 48 49 |
# File 'lib/hpricot_ext.rb', line 47 def has_style?(key) properties.has_key?(key) end |
#properties ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/hpricot_ext.rb', line 59 def properties return {} if not @element.has_attribute?("style") @element.get_attribute("style").split(";").inject({}) do |hash,v| v = v.split(":") hash.update v.first.strip => v.last.strip end end |
#to_h ⇒ Object
55 56 57 |
# File 'lib/hpricot_ext.rb', line 55 def to_h properties end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/hpricot_ext.rb', line 51 def to_s properties.to_s end |