Class: Deface::Sources::Cut

Inherits:
Source
  • Object
show all
Defined in:
lib/deface/sources/cut.rb

Class Method Summary collapse

Methods inherited from Source

to_sym

Class Method Details

.execute(override) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/deface/sources/cut.rb', line 4

def self.execute(override)
  cut = override.args[:cut]
  if cut.is_a? Hash
    range = Deface::Matchers::Range.new('Cut', cut[:start], cut[:end]).matches(override.parsed_document).first
    range.map &:remove

    Deface::Parser.undo_erb_markup! range.map(&:to_s).join

  else
    element = override.parsed_document.css(cut).first

    if element.nil?
      override.failure = "failed to match :cut selector '#{cut}'"
      nil
    else
      Deface::Parser.undo_erb_markup! element.remove.to_s.clone
    end
  end
end