Class: Enchant
- Inherits:
-
Object
- Object
- Enchant
- Defined in:
- lib/enchant.rb
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
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(url) ⇒ Enchant
constructor
A new instance of Enchant.
- #list(wordlist) ⇒ Object
- #ping ⇒ Object
- #to_s ⇒ Object
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
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/enchant.rb', line 7 def code @code end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/enchant.rb', line 7 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/enchant.rb', line 7 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
62 63 64 |
# File 'lib/enchant.rb', line 62 def self.version() "Enchant v"+VERSION end |
Instance Method Details
#fuzz ⇒ Object
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 |
#ping ⇒ Object
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_s ⇒ Object
58 59 60 |
# File 'lib/enchant.rb', line 58 def to_s() "Enchant v"+VERSION+" - (C) 2010, [email protected]" end |