Class: Ronin::Web::CLI::Commands::Diff Private

Inherits:
Ronin::Web::CLI::Command show all
Includes:
CommandKit::Terminal
Defined in:
lib/ronin/web/cli/commands/diff.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Diffs two web pages.

Usage

ronin-web diff [options] {URL | FILE} {URL | FILE}

Arguments

URL | FILE                       The original URL or file
URL | FILE                       The modified URL or file

Options

-h, --help                       Print help information

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#read(source) ⇒ String, File

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a web page.

Parameters:

  • source (String)

    The URL or file path of the web page.

Returns:

  • (String, File)

    The contents of the web page.

Since:

  • 1.0.0



94
95
96
97
98
99
100
101
# File 'lib/ronin/web/cli/commands/diff.rb', line 94

def read(source)
  if source.start_with?('https://') ||
     source.start_with?('http://')
    Support::Network::HTTP.get_body(source)
  else
    File.new(source)
  end
end

#run(page1, page2) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the ronin-web diff command.

Parameters:

  • page1 (String)

    The URL or file path of the original page.

  • page2 (String)

    The URL or file path of the modified page.

Since:

  • 1.0.0



74
75
76
77
78
79
80
81
82
83
# File 'lib/ronin/web/cli/commands/diff.rb', line 74

def run(page1,page2)
  doc1 = Nokogiri::HTML(read(page1))
  doc2 = Nokogiri::HTML(read(page2))

  doc1.diff(doc2) do |change,node|
    unless change == ' '
      puts "#{change} #{node}"
    end
  end
end