Class: NokogiriStyles::Propset
- Inherits:
-
Object
- Object
- NokogiriStyles::Propset
- Defined in:
- lib/nokogiri-styles/propset.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(style_string) ⇒ Propset
constructor
A new instance of Propset.
- #to_s ⇒ Object
Constructor Details
#initialize(style_string) ⇒ Propset
Returns a new instance of Propset.
3 4 5 6 |
# File 'lib/nokogiri-styles/propset.rb', line 3 def initialize(style_string) @properties = parse_properties(style_string) @mapping = make_mapping(@properties) end |
Instance Method Details
#[](key) ⇒ Object
14 15 16 17 |
# File 'lib/nokogiri-styles/propset.rb', line 14 def [](key) property = @mapping[key] property.nil? ? nil : property[:value] end |
#[]=(key, val) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nokogiri-styles/propset.rb', line 19 def []=(key, val) return self.delete(key) if val.nil? property = @mapping[key] if property.nil? property = {:key => key} @properties << property @mapping[key] = property end @mapping[key][:value] = val end |
#delete(key) ⇒ Object
30 31 32 33 |
# File 'lib/nokogiri-styles/propset.rb', line 30 def delete(key) @mapping.delete(key) @properties.reject! { |p| p[:key] == key } end |
#to_s ⇒ Object
8 9 10 11 12 |
# File 'lib/nokogiri-styles/propset.rb', line 8 def to_s @properties. map { |p| [p[:key], p[:value]].join(': ') }. join('; ') end |