class RBeautify::BlockStart

Attributes

after_match[R]
block_matcher[R]
line_number[R]
match[R]
offset[R]
parent[R]

Public Class Methods

first_common_ancestor(first, second) click to toggle source
# 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
new(block_matcher, parent, line_number, offset, match, after_match) click to toggle source
# 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

Public Instance Methods

ancestors() click to toggle source
# 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?() click to toggle source
# File lib/ruby-beautify/lib/ruby-beautify/block_start.rb, line 61
def end_is_implicit?
  block_matcher.end_is_implicit?
end
end_offset() click to toggle source
# File lib/ruby-beautify/lib/ruby-beautify/block_start.rb, line 26
def end_offset
  offset + match.length
end
format_content?() click to toggle source
# File lib/ruby-beautify/lib/ruby-beautify/block_start.rb, line 41
def format_content?
  block_matcher.format_content?
end
indent_end_line?() click to toggle source
# File lib/ruby-beautify/lib/ruby-beautify/block_start.rb, line 49
def indent_end_line?
  block_matcher.indent_end_line?(self)
end
indent_size() click to toggle source
# File lib/ruby-beautify/lib/ruby-beautify/block_start.rb, line 57
def indent_size
  block_matcher.indent_size(self)
end
name() click to toggle source
# File lib/ruby-beautify/lib/ruby-beautify/block_start.rb, line 65
def name
  block_matcher.name
end
parse_block_end(string, offset) click to toggle source
# 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?() click to toggle source
# 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) click to toggle source

Returns true if strict ancestor of

# 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_size() click to toggle source
# 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

Private Instance Methods

ends?() click to toggle source
# File lib/ruby-beautify/lib/ruby-beautify/block_start.rb, line 83
def ends?
  block_matcher.ends?
end
escape_character?() click to toggle source
# File lib/ruby-beautify/lib/ruby-beautify/block_start.rb, line 91
def escape_character?
  block_matcher.escape_character?
end
negate_ends_match?() click to toggle source
# File lib/ruby-beautify/lib/ruby-beautify/block_start.rb, line 87
def negate_ends_match?
  block_matcher.negate_ends_match?
end
parse_explicit_block_end(string, offset) click to toggle source
# File lib/ruby-beautify/lib/ruby-beautify/block_start.rb, line 95
def parse_explicit_block_end(string, offset)
  block_end = nil

  if ends?

    if match = block_matcher.ends.match(string)
      unless negate_ends_match?
        if escape_character? &&
            ((escape_chars = match.pre_match.match(/\\*$/)) && (escape_chars[0].size % 2 == 1))
          # If there are an odd number of escape characters just before
          # the match then this match should be skipped
          return parse_explicit_block_end(match.post_match, offset + escape_chars[0].size + match[0].length)
        else
          return RBeautify::BlockEnd.new(self, offset + match.begin(0), match[0], match.post_match)
        end
      end
    elsif negate_ends_match?
      return RBeautify::BlockEnd.new(self, offset, '', string)
    end

  end
end