Class: Templatecop::RubyClipper::PrecedingKeywordRemover

Inherits:
Object
  • Object
show all
Defined in:
lib/templatecop/ruby_clipper.rb

Constant Summary collapse

REGEXP =
/
  \A
  (?:
    begin
    | case
    | else
    | elsif
    | ensure
    | if
    | rescue
    | unless
    | until
    | when
    | while
    | for[ \t]+\w+[ \t]+in
  )
  [ \t]
/x.freeze

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ PrecedingKeywordRemover

Returns a new instance of PrecedingKeywordRemover.

Parameters:

  • code (String)


47
48
49
# File 'lib/templatecop/ruby_clipper.rb', line 47

def initialize(code)
  @code = code
end

Instance Method Details

#callHash

Returns:

  • (Hash)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/templatecop/ruby_clipper.rb', line 52

def call
  data = @code.match(REGEXP)
  if data
    offset = data[0].length
    {
      code: @code[offset..],
      offset: offset
    }
  else
    {
      code: @code,
      offset: 0
    }
  end
end