Sha256: 09f7bdfa16cf6fd0b4c61158d09f97e5a051ed162982a0edce2c4a8375b28806

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

module Hieracles
  class Format
    def initialize(node)
      @node = node
    end

    def info(_)
      "#{__callee__} not implemented, please inherit from the Hieracles::Format class to implement a format.\n"
    end

    def files(_)
      "#{__callee__} not implemented, please inherit from the Hieracles::Format class to implement a format.\n"
    end

    def paths(_)
      "#{__callee__} not implemented, please inherit from the Hieracles::Format class to implement a format.\n"
    end

    def params(args)
      show_params(true, args)
    end

    def allparams(args)
      show_params(false, args)
    end

    def show_params(without_common, args)
      filter = args[0]
      output = build_head(without_common)
      @node.params(without_common).each do |k, v|
        output << build_params_line(k, v, filter)
      end
      output
    end

    def modules(args)
      output = ''
      @node.modules.each do |k, v|
        output << build_modules_line(k, v)
      end
      output
    end

  protected

    def build_head(without_common)
      "#{__callee__} not implemented, please inherit from the Hieracles::Format class to implement a format.\n"
    end

    def build_params_line(key, value, filter)
      "#{__callee__} not implemented, please inherit from the Hieracles::Format class to implement a format.\n"
    end

    def build_modules_line(key, value)
      "#{__callee__} not implemented, please inherit from the Hieracles::Format class to implement a format.\n"
    end

    def is_merged?(v)
      v[:value].is_a?(Array) && (v[:value] | v[:merged]) != v[:value]
    end

    def sanitize(v)
      v.to_s.gsub('%', '%%')
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hieracles-0.2.0 lib/hieracles/format.rb