Class: ConvenientService::Utils::String::Tab Private

Inherits:
Support::Command show all
Defined in:
lib/convenient_service/utils/string/tab.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Examples:

Common usage.

ConvenientService::Utils::String::Tab.call("foo\nbar\nbaz")
# => "  foo\n  bar\n  baz"

ConvenientService::Utils::String::Tab.call("foo\nbar\nbaz", tab_size: 4)
# => "    foo\n    bar\n    baz"

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(string, tab_size: 2) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • string (String)
  • tab_size (Integer) (defaults to: 2)

Since:

  • 1.0.0



37
38
39
40
# File 'lib/convenient_service/utils/string/tab.rb', line 37

def initialize(string, tab_size: 2)
  @string = string.to_s
  @tab_size = tab_size
end

Instance Attribute Details

#stringObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



24
25
26
# File 'lib/convenient_service/utils/string/tab.rb', line 24

def string
  @string
end

#tab_sizeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



30
31
32
# File 'lib/convenient_service/utils/string/tab.rb', line 30

def tab_size
  @tab_size
end

Instance Method Details

#callString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Since:

  • 1.0.0



45
46
47
# File 'lib/convenient_service/utils/string/tab.rb', line 45

def call
  string.lines.map { |line| "#{tab}#{line}" }.join
end