Class: Enchant
- Inherits:
-
Object
- Object
- Enchant
- Defined in:
- lib/enchant.rb
Constant Summary collapse
- VERSION =
'0.3.0'
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#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_sane? ⇒ Boolean
- #list(wordlist) ⇒ Object
- #ping ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*urls) ⇒ Enchant
Returns a new instance of Enchant.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/enchant.rb', line 12 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.rb', line 7 def code @code end |
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/enchant.rb', line 8 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
8 9 10 |
# File 'lib/enchant.rb', line 8 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
7 8 9 |
# File 'lib/enchant.rb', line 7 def server @server end |
Class Method Details
.version ⇒ Object
81 82 83 84 |
# File 'lib/enchant.rb', line 81 def self.version() @version = File.exist?('VERSION') ? File.read('VERSION') : VERSION "Enchant v"+@version end |
Instance Method Details
#fuzz ⇒ Object
46 47 48 49 |
# File 'lib/enchant.rb', line 46 def fuzz(*) # in future some perturbation will be done here @list end |
#get(path) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/enchant.rb', line 51 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 |
#is_sane? ⇒ Boolean
31 32 33 |
# File 'lib/enchant.rb', line 31 def is_sane? @sane end |
#list(wordlist) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/enchant.rb', line 35 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 ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/enchant.rb', line 65 def ping(*) Net::HTTP.start(host, port) { |http| response = http.head("/") response.each { |key,val| if "server" == key @server=val end } } end |
#to_s ⇒ Object
77 78 79 |
# File 'lib/enchant.rb', line 77 def to_s() "Enchant v"+VERSION+" - (C) 2010, [email protected]" end |