Class: Enchant::Engine

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#codeObject (readonly)

Returns the value of attribute code.



7
8
9
# File 'lib/enchant/engine.rb', line 7

def code
  @code
end

#domainObject

Returns the value of attribute domain.



8
9
10
# File 'lib/enchant/engine.rb', line 8

def domain
  @domain
end

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/enchant/engine.rb', line 8

def host
  @host
end

#portObject

Returns the value of attribute port.



8
9
10
# File 'lib/enchant/engine.rb', line 8

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



7
8
9
# File 'lib/enchant/engine.rb', line 7

def server
  @server
end

Instance Method Details

#fuzzObject



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

Returns:

  • (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

Returns:

  • (Boolean)


63
64
65
# File 'lib/enchant/engine.rb', line 63

def up?(site)
  Net::HTTP.new(site).head('/').kind_of? Net::HTTPOK
end