Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added list method

  • Loading branch information...
commit e678c586b25ff33e31f48ba2e38448cd04ea20e2 1 parent e9bec48
@prikha authored
View
10 .irbrc
@@ -0,0 +1,10 @@
+unless defined?(reload!)
+ $files = []
+ def load!(file)
+ $files << file
+ load file
+ end
+ def reload!
+ $files.each { |f| load f }
+ end
+end
View
7 lib/dickens.rb
@@ -1,4 +1,5 @@
require "dickens/version"
+require "dickens/list_items"
require 'rbconfig'
require RbConfig::CONFIG['target_os'] == 'mingw32' && !(RUBY_VERSION =~ /1.9/) ? 'win32/open3' : 'open3'
@@ -38,14 +39,12 @@ class StarDict
class << self
def find(word)
- word.to_s
- command = [@@executable, prepare_options, word].join(" ")
+ command = [@@executable, prepare_options, word.to_s].join(" ")
invoke(command).join
end
def list
- command = [@@executable, "--list-dicts"].join(" ")
- puts invoke(command)
+ Dickens::ListItem.parse invoke([@@executable, "--list-dicts"].join(" "))
end
protected
View
5 lib/dickens/find_items.rb
@@ -0,0 +1,5 @@
+module Dickens
+ class FindItem
+
+ end
+end
View
17 lib/dickens/list_items.rb
@@ -0,0 +1,17 @@
+module Dickens
+ class ListItem
+ attr_accessor :name, :word_count
+ def self.parse(stdout)
+ stdout.map!{|item|
+ next if stdout.index(item)==0
+ self.new(item)
+ }.compact!
+ end
+
+ def initialize(string)
+ @name, @word_count = string.gsub(/\n/,"").split(" ")
+ @word_count= @word_count.to_i
+ end
+
+ end
+end
View
2  spec/dickens/dickens_spec.rb
@@ -8,5 +8,7 @@
it "should list the dictionaries" do
Dickens::StarDict.list.should be_a(Array)
+ Dickens::StarDict.list.count.should be Dickens::StarDict.list.compact.count
+ Dickens::StarDict.list.first.should be_a(Dickens::ListItem)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.