Class Amrita::Attr
In: lib/amrita/node.rb
Parent: Object

represents a key value pair in HTML Element

Methods

==   clone   key   key_symbol   new   to_ruby  

Attributes

value  [RW] 

Public Class methods

[Source]

# File lib/amrita/node.rb, line 31
    def initialize(key, value=nil)
      @key = key.intern
      case value
      when nil
        @value = nil
      when String
        @value = value.frozen_copy
      else
        @value = value.to_s.freeze 
      end
    end

Public Instance methods

[Source]

# File lib/amrita/node.rb, line 47
    def ==(x)
      return false unless x.kind_of?(Attr)
      x.key_symbol == @key and x.value == @value
    end

[Source]

# File lib/amrita/node.rb, line 43
    def clone
      Attr.new(@key, @value)
    end

return key as String

[Source]

# File lib/amrita/node.rb, line 53
    def key
      @key.id2name
    end

return key as Symbol

[Source]

# File lib/amrita/node.rb, line 58
    def key_symbol
      @key
    end

[Source]

# File lib/amrita/node.rb, line 62
    def to_ruby
      if key =~ /^\w+$/
        if value
          "a(:#{key}, \"#{value}\")"
        else
          "a(:#{key})"
        end
      else
        if value
          "a(\"#{key}\", \"#{value}\")"
        else
          "a(\"#{key}\")"
        end
      end
    end

[Validate]