Class: RBeautify::BlockStart

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block_matcher, parent, line_number, offset, match, after_match) ⇒ BlockStart

Returns a new instance of BlockStart.



17
18
19
20
21
22
23
24
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 17

def initialize(block_matcher, parent, line_number, offset, match, after_match)
  @block_matcher = block_matcher
  @parent = parent
  @offset = offset
  @match = match
  @after_match = after_match
  @line_number = line_number
end

Instance Attribute Details

#after_matchObject (readonly)

Returns the value of attribute after_match.



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

def after_match
  @after_match
end

#block_matcherObject (readonly)

Returns the value of attribute block_matcher.



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

def block_matcher
  @block_matcher
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



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

def line_number
  @line_number
end

#matchObject (readonly)

Returns the value of attribute match.



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

def match
  @match
end

#offsetObject (readonly)

Returns the value of attribute offset.



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

def offset
  @offset
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

Class Method Details

.first_common_ancestor(first, second) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 8

def first_common_ancestor(first, second)
  if first.nil? || second.nil?
    nil
  else
    (first.ancestors & second.ancestors).last
  end
end

Instance Method Details

#ancestorsObject



74
75
76
77
78
79
80
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 74

def ancestors
  if parent
    parent.ancestors + [self]
  else
    [self]
  end
end

#end_is_implicit?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 61

def end_is_implicit?
  block_matcher.end_is_implicit?
end

#end_offsetObject



26
27
28
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 26

def end_offset
  offset + match.length
end

#format_content?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 41

def format_content?
  block_matcher.format_content?
end

#indent_end_line?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 49

def indent_end_line?
  block_matcher.indent_end_line?(self)
end

#indent_sizeObject



57
58
59
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 57

def indent_size
  block_matcher.indent_size(self)
end

#nameObject



65
66
67
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 65

def name
  block_matcher.name
end

#parse_block_end(string, offset) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 30

def parse_block_end(string, offset)
  block_end = parse_explicit_block_end(string, offset)

  # Handle case where end is implicit
  if block_end.nil? && end_is_implicit? && parent
    block_end = parent.parse_block_end(string, offset)
  end

  block_end
end

#parse_content?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 45

def parse_content?
  block_matcher.parse_content?
end

#strict_ancestor_of?(block_start) ⇒ Boolean

Returns true if strict ancestor of

Returns:

  • (Boolean)


70
71
72
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 70

def strict_ancestor_of?(block_start)
  block_start && block_start.parent && (self == block_start.parent || strict_ancestor_of?(block_start.parent))
end

#total_indent_sizeObject



53
54
55
# File 'lib/ruby-beautify/lib/ruby-beautify/block_start.rb', line 53

def total_indent_size
  parent.nil? ? indent_size : parent.total_indent_size + indent_size
end