Class: ShellExplain::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/shell_explain.rb

Class Method Summary collapse

Class Method Details

.get_command(doc) ⇒ Object

help-num



18
19
20
21
22
23
# File 'lib/shell_explain.rb', line 18

def get_command(doc)
  doc.xpath("//span[@helpref]").inject({}) do|cmds, node|
    cmds[node.text] = node.attributes["helpref"].value
    cmds
  end
end

.get_data(cmd) ⇒ Object



10
11
12
13
14
15
# File 'lib/shell_explain.rb', line 10

def get_data(cmd)
	 explain_shell_url = "http://explainshell.com/explain?cmd="
 uri = URI("#{explain_shell_url}#{CGI.escape(cmd)}")
 html = Net::HTTP.get_response(uri).body
 Nokogiri::HTML(html)
end

.get_explain(doc) ⇒ Object



25
26
27
28
29
30
# File 'lib/shell_explain.rb', line 25

def get_explain(doc)
 data = doc.xpath("//table[@id='help']//pre").inject([]) do|exps, node|
   exps << node.children.text
 end
 data
end