Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
prikha
committed
Sep 28, 2012
0 parents
commit e56022b
Showing
10 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.gem | ||
.bundle | ||
Gemfile.lock | ||
pkg/* | ||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in dickens.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2012 Sergey Prikhodko | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#Dickens | ||
## is for dictionaries | ||
TODO: write some readme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require "rake" | ||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "dickens/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "dickens" | ||
s.version = Dickens::VERSION | ||
s.authors = ["prikha"] | ||
s.email = ["sergey@zengile.com"] | ||
s.homepage = "http://github.com/prikha/dickens" | ||
s.summary = %q{TODO: Write a gem summary} | ||
s.description = %q{TODO: Write a gem description} | ||
|
||
s.rubyforge_project = "dickens" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
|
||
s.add_development_dependency "rspec" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
require "dickens/version" | ||
|
||
require 'rbconfig' | ||
require RbConfig::CONFIG['target_os'] == 'mingw32' && !(RUBY_VERSION =~ /1.9/) ? 'win32/open3' : 'open3' | ||
|
||
require 'active_support/core_ext/class/attribute_accessors' | ||
|
||
begin | ||
require 'active_support/core_ext/object/blank' | ||
rescue LoadError | ||
require 'active_support/core_ext/blank' | ||
end | ||
|
||
module Dickens | ||
class StarDict | ||
@@executable = "sdcv" | ||
@@config = { | ||
:use_dict => false, | ||
:utf8_input => true, | ||
:utf8_output => true, | ||
:non_interactive => true, | ||
:data_dir=>false | ||
} | ||
cattr_accessor :config, :executable | ||
|
||
|
||
#Использование: | ||
# sdcv [ПАРАМЕТР...] words | ||
# | ||
#Параметры приложения: | ||
#-v, --version display version information and exit | ||
#-l, --list-dicts display list of available dictionaries and exit | ||
#-u, --use-dict=bookname for search use only dictionary with this bookname | ||
#-n, --non-interactive for use in scripts | ||
#-0, --utf8-output output must be in utf8 | ||
#-1, --utf8-input input of sdcv in utf8 | ||
#-2, --data-dir=path/to/dir use this directory as path to stardict data directory | ||
|
||
class << self | ||
def find(word) | ||
word.to_s | ||
invoke(word) | ||
end | ||
|
||
protected | ||
|
||
def invoke(word) | ||
command = [@@executable, prepare_options, word].join(" ") | ||
stdin, stdout, stderr = Open3.popen3(command) | ||
return stdout.readlines.join | ||
end | ||
|
||
def prepare_options | ||
raise WrongFormatError unless @@config.is_a? Hash | ||
options = normalize_options(@@config) | ||
options.flatten | ||
end | ||
|
||
def normalize_options(options) | ||
normalized_options = {} | ||
options.each do |key, value| | ||
next unless value | ||
normalized_key = "--#{normalize_arg key}" | ||
normalized_options[normalized_key] = normalize_value(value) | ||
end | ||
normalized_options | ||
end | ||
|
||
def normalize_arg(arg) | ||
arg.to_s.downcase.gsub(/[^a-z0-9]/,'-') | ||
end | ||
|
||
def normalize_value(value) | ||
value.is_a?(TrueClass) ? nil : value.to_s | ||
end | ||
|
||
end | ||
|
||
|
||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Dickens | ||
VERSION = "0.0.1alpha" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#coding:utf-8 | ||
require 'spec_helper' | ||
|
||
describe Dickens::StarDict do | ||
it "should get the result" do | ||
Dickens::StarDict.find("петля").should_not be_nil | ||
end | ||
|
||
it "should list the dictionaries" do | ||
Dickens::StarDict.list.should be_a(Array) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'dickens' |