Class: Templatecop::RubyClipper::PrecedingKeywordRemover
- Inherits:
-
Object
- Object
- Templatecop::RubyClipper::PrecedingKeywordRemover
- 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
- #call ⇒ Hash
-
#initialize(code) ⇒ PrecedingKeywordRemover
constructor
A new instance of PrecedingKeywordRemover.
Constructor Details
#initialize(code) ⇒ PrecedingKeywordRemover
Returns a new instance of PrecedingKeywordRemover.
47 48 49 |
# File 'lib/templatecop/ruby_clipper.rb', line 47 def initialize(code) @code = code end |
Instance Method Details
#call ⇒ 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 |