Class: Ronin::Web::CLI::Commands::Diff Private
- Inherits:
-
Ronin::Web::CLI::Command
- Object
- Core::CLI::Command
- Ronin::Web::CLI::Command
- Ronin::Web::CLI::Commands::Diff
- Includes:
- CommandKit::Colors
- 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
-f, --format Pass the format of the URL or files. Supported formats are html and xml. (Default: html)
Instance Method Summary collapse
-
#parse_doc(page) ⇒ Nokogiri::HTML::Document, Nokogiri::XML::Document
private
Loads the given html or xml sources.
-
#print_change(change, node) ⇒ Object
private
Prints a change to the document.
-
#read(source) ⇒ String, File
private
Reads a web page.
-
#run(page1, page2) ⇒ Object
private
Runs the
ronin-web diff
command.
Instance Method Details
#parse_doc(page) ⇒ Nokogiri::HTML::Document, Nokogiri::XML::Document
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.
Loads the given html or xml sources
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ronin/web/cli/commands/diff.rb', line 145 def parse_doc(page) case [:format] when :html Nokogiri::HTML(read(page)) when :xml Nokogiri::XML(read(page)) else raise(NotImplementedError,"unsupported format: #{[:format].inspect}") end end |
#print_change(change, node) ⇒ 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.
Prints a change to the document.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ronin/web/cli/commands/diff.rb', line 105 def print_change(change,node) color = case change when '+' then colors.method(:green) when '-' then colors.method(:red) end content = node.to_s content.each_line(chomp: true) do |line| puts color.call("#{change} #{line}") end end |
#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.
127 128 129 130 131 132 133 134 |
# File 'lib/ronin/web/cli/commands/diff.rb', line 127 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.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ronin/web/cli/commands/diff.rb', line 82 def run(page1,page2) doc1 = parse_doc(page1) doc2 = parse_doc(page2) doc1.diff(doc2) do |change,node| unless change == ' ' # ignroe unchanged nodes print_change(change,node) end end end |