Sha256: b1423c1a1665e6c0ef4a24990ecba29b3b260b06e39dbe9e388d193f24ba46c0

Contents?: true

Size: 1.47 KB

Versions: 12

Compression:

Stored size: 1.47 KB

Contents

module Hieracles
  module Formats
    # format accepting colors
    # for display in the terminal
    class Plain < Hieracles::Format
      include Hieracles::Utils

      def initialize(node)
        @index = {}
        super(node)
      end

      def info(_)
        back = ''
        length = max_key_length(@node.info) + 2
        @node.info.each do |k, v|
          back << format("%-#{length}s %s\n", k, v)
        end
        back
      end

      def files(_)
        @node.files.join("\n") + "\n"
      end

      def paths(_)
        @node.paths.join("\n") + "\n"
      end

      def build_head(without_common)
        output = ''
        @node.files(without_common).each_with_index do |f, i|
          output << "[#{i}] #{f}\n"
          @index[f] = i
        end
        "#{output}\n"
      end

      def build_params_line(key, value, filter)
        output = ''
        if !filter || Regexp.new(filter).match(key)
          first = value.shift
          filecolor_index = @index[first[:file]]
          output << "[#{filecolor_index}] #{key} #{first[:value]}\n"
          while value.count > 0
            overriden = value.shift
            filecolor_index = @index[overriden[:file]]
            output << "    [#{filecolor_index}] #{key} #{overriden[:value]}\n"
          end
        end
        output
      end

      def build_modules_line(key, value)
        length = max_key_length(@node.modules) + 3
        format("%-#{length}s %s\n", key, value)
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hieracles-0.1.5 lib/hieracles/formats/plain.rb
hieracles-0.1.4 lib/hieracles/formats/plain.rb
hieracles-0.1.3 lib/hieracles/formats/plain.rb
hieracles-0.1.2 lib/hieracles/formats/plain.rb
hieracles-0.1.1 lib/hieracles/formats/plain.rb
hieracles-0.1.0 lib/hieracles/formats/plain.rb
hieracles-0.0.6 lib/hieracles/formats/plain.rb
hieracles-0.0.5 lib/hieracles/formats/plain.rb
hieracles-0.0.4 lib/hieracles/formats/plain.rb
hieracles-0.0.3 lib/hieracles/formats/plain.rb
hieracles-0.0.2 lib/hieracles/formats/plain.rb
hieracles-0.0.1 lib/hieracles/formats/plain.rb