Sha256: d9f77d5a8c05fbe5d08616d59bccca93ed310f4497b943051ba2f028fff750b3

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

require_relative('environment.rb')
class Array
    attr_accessor :env
    def intialize env=nil
      @env=env
      @env=Environment.new() if @env.nil? 
      @env=Environmnet.new() if !@env.kind_of?(Environment)
    end

    def execute value=nil
      @env=Environment.new() if @env.nil? 
      i=0
      while i < self.length
        self[i]=Command.new({ :input => self[i], :quiet => true }) if(self[i].is_a?(String))
        self[i]=Command.new(self[i]) if(self[i].is_a?(Hash) && !self[i].is_a?(Command))

        if(!value.nil? && value.is_a?(Hash))
          value.each{|k,v|self[i][k]=v}
        end

        #self[i].execute if(self[i].is_a?(Command))
        if(self[i].is_a?(Command))
          self[i].execute
          @env.out self[i].summary
        end

        i=i+1
      end
    end

    def add command
      self << command if !has_command? command
    end

    def has_command? command
      return true if(command.kind_of?(String) && !include?(command))
      if(command.kind_of?(Command))
        self.each{|c|
          if c.kind_of?(String)
            return true if command[:input] == c
          else
            return true if(c[:input] == command[:input])
          end
        }
      end
      false
    end

    def add_quiet command
      add Command.new({ :input => command, :quiet => true })
    end

    def add_passive command
      add Command.new({ :input => command, :quiet => true, :ignore_failure => true })
    end

    def to_html
      html=Array.new
      html << '<div>'
      self.each{|e|
        html << e.to_html if e.respond_to?(:to_html)
      }
      html << '</div>'
      html.join
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dev-2.0.270 lib/base/array.rb