123456789_123456789_123456789_123456789_123456789_

Module: RuboCop::Cop::PercentLiteral

Overview

Common functionality for handling percent literals.

Constant Summary

RangeHelp - Included

BYTE_ORDER_MARK, NOT_GIVEN

Instance Method Summary

RangeHelp - Included

#add_range, #column_offset_between,
#contents_range

A range containing only the contents of a literal with delimiters (e.g.

#directions,
#effective_column

Returns the column attribute of the range, except if the range is on the first line and there’s a byte order mark at the beginning of that line, in which case 1 is subtracted from the column value.

#final_pos, #move_pos, #move_pos_str, #range_between, #range_by_whole_lines, #range_with_comments, #range_with_comments_and_lines, #range_with_surrounding_comma, #range_with_surrounding_space, #source_range

Instance Method Details

#begin_source(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/percent_literal.rb', line 23

def begin_source(node)
  node.loc.begin.source if node.loc.respond_to?(:begin) && node.loc.begin
end

#percent_literal?(node) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/percent_literal.rb', line 11

def percent_literal?(node)
  return false unless (begin_source = begin_source(node))

  begin_source.start_with?('%')
end

#process(node, *types) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/percent_literal.rb', line 17

def process(node, *types)
  return unless percent_literal?(node) && types.include?(type(node))

  on_percent_literal(node)
end

#type(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/percent_literal.rb', line 27

def type(node)
  node.loc.begin.source[0..-2]
end