Sha256: 74f7bbf2357c6903076ad98b1c43469df9b88f98d8629e3a4cb660938cf50cec

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module Yapfac
class  Apache
class  Scope

  attr_reader :name, :params, :parent

  def initialize(name = nil, params = nil, parent = nil)
    @name   = name
    @params = params.nil? ? Array.new : params.split(/\s+/)
    @parent = parent

    @directives = Array.new
    @scopes     = Array.new
  end

  def add_directive(line)
    @directives.push(line)
  end

  def add_scope(scope)
    if scope == self
      raise "Scope can not be a child of itsself."
    end

    @scopes.push(scope)
  end

  def to_h
    return({
      name: @name,
      params: @params,
      directives: @directives.collect(&:to_h),
      scopes: @scopes.collect(&:to_h)
    })
  end

  def to_s
    # TODO: Figure out a cleaner indentation method.

    out = Array.new
    tab = @parent.nil? ? "" : "\t"

    unless parent.nil?
      out << "<#{@name} #{@params.join(' ')}>"
    end

    unless @directives.empty?
      out << @directives.collect { |d| d.to_s.prepend(tab) }
    end

    unless @scopes.empty?
      out << @scopes.collect { |s| s.to_s.split("\n").collect { |v| v.prepend(tab) }.join("\n") }
    end

    unless parent.nil?
      out << "</#{@name}>"
    end

    return out.join("\n")
  end

end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yapfac-0.1.0 lib/yapfac/apache/scope.rb