Class: Bashly::Script::Formatter
- Inherits:
-
Object
- Object
- Bashly::Script::Formatter
- Defined in:
- lib/bashly/script/formatter.rb
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
Instance Method Summary collapse
- #formatted_script ⇒ Object
-
#initialize(script, mode: nil) ⇒ Formatter
constructor
A new instance of Formatter.
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
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
7 8 9 |
# File 'lib/bashly/script/formatter.rb', line 7 def mode @mode end |
#script ⇒ Object (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_script ⇒ Object
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 |