Class: Enchant
- Inherits:
-
Object
- Object
- Enchant
- Defined in:
- lib/enchant.rb
Constant Summary collapse
- VERSION =
'0.4.0'
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.
Class Method Summary collapse
Instance Method Summary collapse
- #fuzz ⇒ Object
- #get(path) ⇒ Object
-
#initialize(*urls) ⇒ Enchant
constructor
A new instance of Enchant.
- #is_alive? ⇒ Boolean
- #is_sane? ⇒ Boolean
- #list(wordlist) ⇒ Object
- #ping?(host) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(*urls) ⇒ Enchant
Returns a new instance of Enchant.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/enchant.rb', line 15 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.
10 11 12 |
# File 'lib/enchant.rb', line 10 def code @code end |
#domain ⇒ Object
Returns the value of attribute domain.
11 12 13 |
# File 'lib/enchant.rb', line 11 def domain @domain end |
#host ⇒ Object
Returns the value of attribute host.
11 12 13 |
# File 'lib/enchant.rb', line 11 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
11 12 13 |
# File 'lib/enchant.rb', line 11 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
10 11 12 |
# File 'lib/enchant.rb', line 10 def server @server end |
Class Method Details
.version ⇒ Object
93 94 95 96 |
# File 'lib/enchant.rb', line 93 def self.version() @version = File.exist?('VERSION') ? File.read('VERSION') : VERSION "Enchant v"+@version end |
Instance Method Details
#fuzz ⇒ Object
49 50 51 52 |
# File 'lib/enchant.rb', line 49 def fuzz(*) # in future some perturbation will be done here @list end |
#get(path) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/enchant.rb', line 54 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_alive? ⇒ Boolean
69 70 71 |
# File 'lib/enchant.rb', line 69 def is_alive? code.to_i==200 end |
#is_sane? ⇒ Boolean
34 35 36 |
# File 'lib/enchant.rb', line 34 def is_sane? @sane end |
#list(wordlist) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/enchant.rb', line 38 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 |
#ping?(host) ⇒ Boolean
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/enchant.rb', line 73 def ping?(host) # TCP pinging if Ping.pingecho(host) return true end #else # icmp = Net::Ping::ICMP.new(host) # if icmp.ping? # return true # else # return false # end #end false end |
#to_s ⇒ Object
89 90 91 |
# File 'lib/enchant.rb', line 89 def to_s() "Enchant v"+VERSION+" - (C) 2010, [email protected]" end |