Class: Enchant::Engine
- Inherits:
-
Object
- Object
- Enchant::Engine
- Defined in:
- lib/enchant/engine.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #fuzz ⇒ Object
- #get(path) ⇒ Object
-
#initialize(*urls) ⇒ Engine
constructor
A new instance of Engine.
- #is_sane? ⇒ Boolean
- #list(wordlist) ⇒ Object
- #up?(site) ⇒ Boolean
Constructor Details
#initialize(*urls) ⇒ Engine
Returns a new instance of Engine.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/enchant/engine.rb', line 10 def initialize(*urls) url = urls.pop || "" if url != "" tmp = URI.parse(url) @host = tmp.host @port = tmp.port if @host == nil && @port == nil @sane = nil else @sane = 1 end else @sane = 1 end end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/enchant/engine.rb', line 7 def code @code end |
#domain ⇒ Object
Returns the value of attribute domain.
8 9 10 |
# File 'lib/enchant/engine.rb', line 8 def domain @domain end |
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/enchant/engine.rb', line 8 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
8 9 10 |
# File 'lib/enchant/engine.rb', line 8 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
7 8 9 |
# File 'lib/enchant/engine.rb', line 7 def server @server end |
Instance Method Details
#fuzz ⇒ Object
43 44 45 46 |
# File 'lib/enchant/engine.rb', line 43 def fuzz(*) # in future some perturbation will be done here @list end |
#get(path) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/enchant/engine.rb', line 48 def get(path) http = Net::HTTP.new(host, port) begin response = http.get(path) @code = response.code rescue Net::HTTPBadResponse puts #{$!} @code=-1 rescue Errno::ETIMEDOUT puts #{$!} @code=-1 end @code end |
#is_sane? ⇒ Boolean
28 29 30 |
# File 'lib/enchant/engine.rb', line 28 def is_sane? @sane end |
#list(wordlist) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/enchant/engine.rb', line 32 def list(wordlist) begin File.open(wordlist, 'r') { |f| @list = f.readlines } rescue Errno::ENOENT puts "It seems the wordlist file is not present (#{wordlist})" @list = nil end end |
#up?(site) ⇒ Boolean
63 64 65 |
# File 'lib/enchant/engine.rb', line 63 def up?(site) Net::HTTP.new(site).head('/').kind_of? Net::HTTPOK end |