Class: Hpricot::Attributes

Inherits:
Object show all
Defined in:
lib/hpricot/tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(e) ⇒ Attributes

Returns a new instance of Attributes.



43
44
45
# File 'lib/hpricot/tag.rb', line 43

def initialize e
  @element = e
end

Instance Attribute Details

#elementObject

Returns the value of attribute element.



42
43
44
# File 'lib/hpricot/tag.rb', line 42

def element
  @element
end

Instance Method Details

#[](k) ⇒ Object



46
47
48
# File 'lib/hpricot/tag.rb', line 46

def [] k
  Hpricot.uxs((@element.raw_attributes || {})[k])
end

#[]=(k, v) ⇒ Object



49
50
51
# File 'lib/hpricot/tag.rb', line 49

def []= k, v
  (@element.raw_attributes ||= {})[k] = v.fast_xs
end

#inspectObject



65
66
67
# File 'lib/hpricot/tag.rb', line 65

def inspect
  to_hash.inspect
end

#to_hashObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/hpricot/tag.rb', line 52

def to_hash
  if @element.raw_attributes
    @element.raw_attributes.inject({}) do |hsh, (k, v)|
      hsh[k] = Hpricot.uxs(v)
      hsh
    end
  else
    {}
  end
end

#to_sObject



62
63
64
# File 'lib/hpricot/tag.rb', line 62

def to_s
  to_hash.to_s
end