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

represents a key value pair in HTML Element

Methods

==   clone   key_symbol   new   to_ruby  

Attributes

key  [R]  @attr_reader [String] 属性名
value  [R]  @attr_reader [String] 属性値

Public Class methods

[Source]

# File lib/amrita/node.rb, line 45
    def initialize key, value = nil
      raise TypeError, "key must be a String/Symbol" if !key.is_a?(String) && !key.is_a?(Symbol)

      @key = key.to_s
      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 68
    def ==(x)
      return false unless x.kind_of?(Attr)
      x.key == @key and x.value == @value
    end

[Source]

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

@return [Symbol] 属性名

[Source]

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

[Source]

# File lib/amrita/node.rb, line 73
    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]