Class: Kube::Ctl::Concat

Inherits:
Object
  • Object
show all
Defined in:
lib/kube/ctl/concat.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer) ⇒ Concat

Returns a new instance of Concat.



9
# File 'lib/kube/ctl/concat.rb', line 9

def initialize(buffer) = @buffer = buffer.to_a

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



6
7
8
# File 'lib/kube/ctl/concat.rb', line 6

def buffer
  @buffer
end

Class Method Details

.call(buffer) ⇒ Object



8
# File 'lib/kube/ctl/concat.rb', line 8

def self.call(buffer) = new(buffer).concat

Instance Method Details

#concatObject



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
# File 'lib/kube/ctl/concat.rb', line 11

def concat
  parts = []

  join_next = false

  buffer.each do |entry|
    case entry
    when :dash
      # Append '-' to previous token; next token joins directly
      parts[-1] = "#{parts.last}-" if parts.last
      join_next = true
    when :slash
      # Append '/' to previous token; next token joins directly
      parts[-1] = "#{parts.last}/" if parts.last
      join_next = true
    when Array
      part = render_entry(entry)
      if join_next
        parts[-1] = "#{parts.last}#{part}"
      else
        parts << part
      end
      join_next = false
    end
  end

  parts.join(" ")
end