Class: StringBuilder::Concat::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/string_builder/concat/default.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer) ⇒ Default

Returns a new instance of Default.



7
# File 'lib/string_builder/concat/default.rb', line 7

def initialize(buffer) = @buffer = buffer

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



4
5
6
# File 'lib/string_builder/concat/default.rb', line 4

def buffer
  @buffer
end

Class Method Details

.call(buffer) ⇒ Object



6
# File 'lib/string_builder/concat/default.rb', line 6

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

Instance Method Details

#concatObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/string_builder/concat/default.rb', line 9

def concat
  buffer.map { |entry|
    case entry
    when :slash then "/"
    when :dash then "-"
    else
      name, args, kwargs = entry
      all_args = args.map(&:inspect)
      all_args.concat(kwargs.map { |k, v| "#{k}: #{v.inspect}" }) if kwargs&.any?
      all_args.empty? ? name : "#{name}(#{all_args.join(', ')})"
    end
  }.join(" ")
end