Sha256: fe3827206cbf2466c942fd486b4b3b27312ac8ed6397475b4adf50ce380c0f7d

Contents?: true

Size: 1.78 KB

Versions: 18

Compression:

Stored size: 1.78 KB

Contents

module Pantograph
  class LaneList
    # Print out the result of `generate`

    def self.output(path)
      puts(generate(path))

      puts("Execute using `pantograph [lane_name]`".yellow)
    end

    def self.generate(path)
      ff = Pantograph::PantFile.new(path)
      lanes = ff.runner.lanes

      output = ""

      all_keys = lanes.keys.reject(&:nil?)
      all_keys.unshift(nil) # because we want root elements on top. always! They have key nil

      all_keys.each do |platform|
        next if (lanes[platform] || []).count == 0

        plat_text = platform
        plat_text = "general" if platform.to_s.empty?
        output += "\n--------- #{plat_text}---------\n".yellow

        value = lanes[platform]
        next unless value

        value.each do |lane_name, lane|
          next if lane.is_private

          output += "----- pantograph #{lane.pretty_name}".green
          if lane.description.count > 0
            output += "\n" + lane.description.join("\n") + "\n\n"
          else
            output += "\n\n"
          end
        end
      end

      output
    end

    def self.output_json(path)
      puts(JSON.pretty_generate(self.generate_json(path)))
    end

    # Returns a hash
    def self.generate_json(path)
      output = {}
      return output if path.nil?
      ff = Pantograph::PantFile.new(path)

      all_keys = ff.runner.lanes.keys

      all_keys.each do |platform|
        next if (ff.runner.lanes[platform] || []).count == 0

        output[platform] ||= {}

        value = ff.runner.lanes[platform]
        next unless value

        value.each do |lane_name, lane|
          next if lane.is_private

          output[platform][lane_name] = {
            description: lane.description.join("\n")
          }
        end
      end

      return output
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
pantograph-0.1.22 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.21 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.20 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.19 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.17 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.16 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.15 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.14 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.13 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.12 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.10 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.8 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.7 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.6 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.4 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.3 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.1 pantograph/lib/pantograph/lane_list.rb
pantograph-0.1.0 pantograph/lib/pantograph/lane_list.rb