Class: RBeautify::Line

Inherits:
Object show all
Defined in:
lib/ruby-beautify/lib/ruby-beautify/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language, content, line_number, original_block = nil, use_tabs = false) ⇒ Line

Returns a new instance of Line.



6
7
8
9
10
11
12
# File 'lib/ruby-beautify/lib/ruby-beautify/line.rb', line 6

def initialize(language, content, line_number, original_block = nil, use_tabs = false)
  @language = language
  @content = content
  @original_block = original_block
  @indent_character = use_tabs ? "\t" : "  "
  @block = BlockMatcher.parse(language, original_block, line_number, stripped, 0)
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/ruby-beautify/lib/ruby-beautify/line.rb', line 4

def block
  @block
end

#contentObject (readonly)

Returns the value of attribute content.



4
5
6
# File 'lib/ruby-beautify/lib/ruby-beautify/line.rb', line 4

def content
  @content
end

#indent_characterObject (readonly)

Returns the value of attribute indent_character.



4
5
6
# File 'lib/ruby-beautify/lib/ruby-beautify/line.rb', line 4

def indent_character
  @indent_character
end

#languageObject (readonly)

Returns the value of attribute language.



4
5
6
# File 'lib/ruby-beautify/lib/ruby-beautify/line.rb', line 4

def language
  @language
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



4
5
6
# File 'lib/ruby-beautify/lib/ruby-beautify/line.rb', line 4

def line_number
  @line_number
end

#original_blockObject (readonly)

Returns the value of attribute original_block.



4
5
6
# File 'lib/ruby-beautify/lib/ruby-beautify/line.rb', line 4

def original_block
  @original_block
end

Instance Method Details

#formatObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby-beautify/lib/ruby-beautify/line.rb', line 14

def format
  if @formatted.nil?
    if format?
      if stripped.length == 0
        @formatted = ""
      else
        @formatted = tab_string + stripped
      end
    else
      @formatted = content
    end
  end

  @formatted
end