Class Amrita::AttrArray
In: lib/amrita/compiler.rb
lib/amrita/node.rb
lib/amrita/node_expand.rb
Parent: Object

Array of Attr s. It can hold body part for using as a model data for Node#expand. Amrita#a() method is a shortcut for Attr.new

Methods

<<   ==   []   []=   amrita_expand_node   amrita_generate_hint   clear   each   inspect   new   size   to_ruby  

Included Modules

Enumerable

Attributes

array  [R]  If you call a() { … }, block yields to body
body  [R]  If you call a() { … }, block yields to body
shared  [RW]  internal use only, never touch it!

true if this instance is shared by two or more elements

Public Class methods

Don‘t use AttrArray.new use a() instead

[Source]

# File lib/amrita/node.rb, line 94
    def initialize(*attrs, &block)
      @array = []
      @shared = false
      attrs.each do |a|
        case a
        when Array, AttrArray
          a.each do |aa|
            self << aa
          end
        when Hash
          attrs[0].each do |k, v|
            self << Attr.new(k, v)
          end
        else
          self << a
        end
      end

      if block_given?
        @body = yield 
      else
        @body = Null
      end
    end

Public Instance methods

add an Attr

[Source]

# File lib/amrita/node.rb, line 134
    def <<(a)
      raise "must be Attr not #{a.class}" unless a.kind_of?(Attr)
      @array << a
    end

AttrArray#== concerns the order of Attr

[Source]

# File lib/amrita/node.rb, line 120
    def ==(x)
      return true if id == x.id
      return false unless x.kind_of?(AttrArray)
      each_with_index do |a, n|
        return false unless a == x[n]
      end
      true
    end

[Source]

# File lib/amrita/node.rb, line 143
    def [](index)
      @array[index]
    end

[Source]

# File lib/amrita/node.rb, line 147
    def []=(index, val)
      @array[index] = val
      val
    end

[Source]

# File lib/amrita/node_expand.rb, line 258
    def amrita_expand_node(n, context)
      raise Amrita::ModelMisMatch(type, n.type)
    end

[Source]

# File lib/amrita/compiler.rb, line 58
    def amrita_generate_hint
      if body
        Amrita::HtmlCompiler::AttrData[body.amrita_generate_hint]
      else
        Amrita::HtmlCompiler::AttrData.new
      end
    end

[Source]

# File lib/amrita/node.rb, line 139
    def clear
      @array.clear
    end

iterate on each Attr

[Source]

# File lib/amrita/node.rb, line 153
    def each(&block)
      @array.each(&block)
    end

[Source]

# File lib/amrita/node.rb, line 129
    def inspect
      to_ruby
    end

[Source]

# File lib/amrita/node.rb, line 157
    def size
      @array.size
    end

[Source]

# File lib/amrita/node.rb, line 161
    def to_ruby
      ret = "a(" + @array.collect {|a| ":#{a.key}, #{a.value}"}.join(", ") + ")"
      case @body
      when nil, Null
      when Node
        ret += body.to_ruby
      else
        ret += body.inspect
      end
      ret
    end

[Validate]