Class: RuboCop::Erb::WhenDecomposer
- Inherits:
-
Object
- Object
- RuboCop::Erb::WhenDecomposer
- Defined in:
- lib/rubocop/erb/when_decomposer.rb
Constant Summary collapse
- REGEXP =
/ \A \s* when[ \t] /x
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Array<RuboCop::Erb::RubyClip>
-
#initialize(processed_source, ruby_clip) ⇒ WhenDecomposer
constructor
A new instance of WhenDecomposer.
Constructor Details
#initialize(processed_source, ruby_clip) ⇒ WhenDecomposer
Returns a new instance of WhenDecomposer.
26 27 28 29 30 31 32 |
# File 'lib/rubocop/erb/when_decomposer.rb', line 26 def initialize( processed_source, ruby_clip ) @processed_source = processed_source @ruby_clip = ruby_clip end |
Class Method Details
.call(processed_source, ruby_clip) ⇒ Array<RuboCop::Erb::RubyClip>
16 17 18 19 20 21 |
# File 'lib/rubocop/erb/when_decomposer.rb', line 16 def call( processed_source, ruby_clip ) new(processed_source, ruby_clip).call end |
Instance Method Details
#call ⇒ Array<RuboCop::Erb::RubyClip>
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubocop/erb/when_decomposer.rb', line 35 def call match_data = @ruby_clip.code.match(REGEXP) if match_data offset = match_data[0].length condition = @ruby_clip.code[offset..].sub(/[ \t]then(?:[ \t].*)?/, '') nodes = parse( " [\n \#{condition}\n ]\n RUBY\n )&.children || []\n\n nodes.map do |child|\n RubyClip.new(\n code: child.location.expression.source,\n offset: @ruby_clip.offset + offset + child.location.expression.begin_pos - 4\n )\n end\n else\n [@ruby_clip]\n end\nend\n" |