Class: Enchant

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

Constant Summary collapse

VERSION =
'0.1.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Enchant

Returns a new instance of Enchant.



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

def initialize(url)
  tmp = URI.parse(url)
  @host = tmp.host
  @port = tmp.port
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



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

def server
  @server
end

Class Method Details

.versionObject



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

def self.version()
  "Enchant v"+VERSION
end

Instance Method Details

#fuzzObject



28
29
30
31
# File 'lib/enchant.rb', line 28

def fuzz(*) 
  # in future some perturbation will be done here
  @list
end

#get(path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/enchant.rb', line 33

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
end

#list(wordlist) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/enchant.rb', line 17

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

#pingObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/enchant.rb', line 47

def ping(*)
  Net::HTTP.start(host, port) { |http| 
    response = http.head("/")
    response.each { |key,val| 
      if "server" == key 
        @server=val
      end 
    }
  }
end

#to_sObject



58
59
60
# File 'lib/enchant.rb', line 58

def to_s() 
  "Enchant v"+VERSION+" - (C) 2010, [email protected]"
end