Sha256: 264c8ef5591dde9ab5864b64038a0c32c22dfe0de3f7842ee74c8f643f4ecf77

Contents?: true

Size: 1.39 KB

Versions: 12

Compression:

Stored size: 1.39 KB

Contents

module Hieracles
  module Formats
    # for db compatibility
    class Csv < Hieracles::Format
      CVS_DELIM = ';'

      def info(_)
        make_csv @node.info.values
      end

      def files(_)
        make_csv @node.files
      end

      def paths(_)
        make_csv @node.paths
      end

      def build_head(without_common)
        output = []
        @node.files(without_common).each do |f|
          output << f
        end
        output += %w(var value overriden)
        make_csv output
      end

      def build_params_line(key, value, filter)
        output = ''
        if !filter || Regexp.new(filter).match(key)
          first = value.shift
          output << make_csv(in_what_file(first[:file]) +
                   [key, first[:value].to_s, '0'])
          while value.count > 0
            overriden = value.shift
            output << make_csv(in_what_file(overriden[:file]) +
                     [key, overriden[:value].to_s, '1'])
          end
        end
        output
      end

      def build_modules_line(key, value)
        make_csv [key, value]
      end

    private

      def make_csv(array)
        array.join(CVS_DELIM) + "\n"
      end

      def in_what_file(file)
        output = []
        @node.files.each do |f|
          if file == f
            output << '1'
          else
            output << '0'
          end
        end
        output
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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