Class: Lookbook::CodeIndenter
- Defined in:
- lib/lookbook/services/code/code_indenter.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(source) ⇒ CodeIndenter
constructor
A new instance of CodeIndenter.
Methods inherited from Service
Constructor Details
#initialize(source) ⇒ CodeIndenter
Returns a new instance of CodeIndenter.
3 4 5 |
# File 'lib/lookbook/services/code/code_indenter.rb', line 3 def initialize(source) @source = source.to_s end |
Instance Method Details
#call ⇒ Object
7 8 9 10 11 12 |
# File 'lib/lookbook/services/code/code_indenter.rb', line 7 def call source = @source.chomp last = source.split(/\r?\n/).last indent = last ? last[/^([ \t]*)/, 1].length : 0 source.gsub(/^[ \t]{#{indent}}/, "") end |