Class: Bashly::Script::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/bashly/script/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script, mode: nil) ⇒ Formatter

Returns a new instance of Formatter.



9
10
11
12
# File 'lib/bashly/script/formatter.rb', line 9

def initialize(script, mode: nil)
  @script = script
  @mode = mode&.to_s || 'internal'
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



7
8
9
# File 'lib/bashly/script/formatter.rb', line 7

def mode
  @mode
end

#scriptObject (readonly)

Returns the value of attribute script.



7
8
9
# File 'lib/bashly/script/formatter.rb', line 7

def script
  @script
end

Instance Method Details

#formatted_scriptObject



14
15
16
17
18
19
20
21
# File 'lib/bashly/script/formatter.rb', line 14

def formatted_script
  case mode
  when 'internal' then script.gsub(/\s+\n/m, "\n\n")
  when 'external' then shfmt_result
  when 'none' then script
  else custom_formatter_result mode
  end
end