Class: Pantograph::LaneList

Inherits:
Object
  • Object
show all
Defined in:
pantograph/lib/pantograph/lane_list.rb

Class Method Summary collapse

Class Method Details

.generate(path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'pantograph/lib/pantograph/lane_list.rb', line 11

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

.generate_json(path) ⇒ Object

Returns a hash



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'pantograph/lib/pantograph/lane_list.rb', line 50

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

.output(path) ⇒ Object

Print out the result of ‘generate`



5
6
7
8
9
# File 'pantograph/lib/pantograph/lane_list.rb', line 5

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

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

.output_json(path) ⇒ Object



45
46
47
# File 'pantograph/lib/pantograph/lane_list.rb', line 45

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