Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added list method

  • Loading branch information...
commit e678c586b25ff33e31f48ba2e38448cd04ea20e2 1 parent e9bec48
Sergey Prikhodko authored
10 .irbrc
... ... @@ -0,0 +1,10 @@
  1 +unless defined?(reload!)
  2 + $files = []
  3 + def load!(file)
  4 + $files << file
  5 + load file
  6 + end
  7 + def reload!
  8 + $files.each { |f| load f }
  9 + end
  10 +end
7 lib/dickens.rb
... ... @@ -1,4 +1,5 @@
1 1 require "dickens/version"
  2 +require "dickens/list_items"
2 3
3 4 require 'rbconfig'
4 5 require RbConfig::CONFIG['target_os'] == 'mingw32' && !(RUBY_VERSION =~ /1.9/) ? 'win32/open3' : 'open3'
@@ -38,14 +39,12 @@ class StarDict
38 39
39 40 class << self
40 41 def find(word)
41   - word.to_s
42   - command = [@@executable, prepare_options, word].join(" ")
  42 + command = [@@executable, prepare_options, word.to_s].join(" ")
43 43 invoke(command).join
44 44 end
45 45
46 46 def list
47   - command = [@@executable, "--list-dicts"].join(" ")
48   - puts invoke(command)
  47 + Dickens::ListItem.parse invoke([@@executable, "--list-dicts"].join(" "))
49 48 end
50 49
51 50 protected
5 lib/dickens/find_items.rb
... ... @@ -0,0 +1,5 @@
  1 +module Dickens
  2 + class FindItem
  3 +
  4 + end
  5 +end
17 lib/dickens/list_items.rb
... ... @@ -0,0 +1,17 @@
  1 +module Dickens
  2 + class ListItem
  3 + attr_accessor :name, :word_count
  4 + def self.parse(stdout)
  5 + stdout.map!{|item|
  6 + next if stdout.index(item)==0
  7 + self.new(item)
  8 + }.compact!
  9 + end
  10 +
  11 + def initialize(string)
  12 + @name, @word_count = string.gsub(/\n/,"").split(" ")
  13 + @word_count= @word_count.to_i
  14 + end
  15 +
  16 + end
  17 +end
2  spec/dickens/dickens_spec.rb
@@ -8,5 +8,7 @@
8 8
9 9 it "should list the dictionaries" do
10 10 Dickens::StarDict.list.should be_a(Array)
  11 + Dickens::StarDict.list.count.should be Dickens::StarDict.list.compact.count
  12 + Dickens::StarDict.list.first.should be_a(Dickens::ListItem)
11 13 end
12 14 end

0 comments on commit e678c58

Please sign in to comment.
Something went wrong with that request. Please try again.