dict_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe DictClient do
4
+ context '#reply_code' do
5
+
6
+ it "catches invalid response codes" do
7
+ DictClient.reply_code('hello', :error).should == :error
8
+ end
9
+
10
+ it "catches invalid response codes throwing exceptions" do
11
+ ->{DictClient.reply_code('hello')}.should raise_error(DictClient::DictError)
12
+ end
13
+
14
+
15
+ it "returns valid response codes" do
16
+ DictClient.reply_code("250 \r\n", :error).should == 250
17
+ end
18
+
19
+
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper.rb'
3
+
4
+ describe DictClient::DictionariesTcpReader do
5
+
6
+ let!(:socket){MockedDictdServerSocket.new}
7
+
8
+ before{socket.write 'show db'}
9
+
10
+
11
+ it 'reads lines correctly' do
12
+ lines = subject.read_from socket
13
+ lines.size.should == 8
14
+
15
+ lines[0].should == "110 94 databases present\n"
16
+ lines[-1].should == %!mech_mime "mech"\n!
17
+ end
18
+ end
19
+
20
+ describe DictClient::WordDefinitionsTcpReader do
21
+
22
+ let!(:socket){MockedDictdServerSocket.new}
23
+
24
+ before{socket.write 'define * "apple"'}
25
+
26
+
27
+ it 'reads lines correctly' do
28
+ lines = subject.read_from socket
29
+ lines.size.should == 19
30
+
31
+ lines[0].should == "150 6 definitions retrieved\r\n"
32
+ lines[1].should == "151 \"apple\" slovnyk_en-uk \"slovnyk_en-uk\"\r\n"
33
+ end
34
+ end
@@ -0,0 +1,99 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper.rb'
3
+
4
+ describe DictClient::SimpleResponse do
5
+
6
+ let(:input){["DEFINE database word -- look up word in database\r\n", "MATCH database strategy word -- match word in database using strategy\r\n", "SHOW DB -- list all accessible databases\r\n", "SHOW DATABASES -- list all accessible databases\r\n", "SHOW STRAT -- list available matching strategies\r\n", "SHOW STRATEGIES -- list available matching strategies\r\n", "SHOW INFO database -- provide information about the database\r\n", "SHOW SERVER -- provide site-specific information\r\n", "OPTION MIME -- use MIME headers\r\n", "CLIENT info -- identify client to server\r\n", "AUTH user string -- provide authentication information\r\n", "STATUS -- display timing information\r\n", "HELP -- display this help information\r\n", "QUIT -- terminate connection\r\n", "\r\n", "The following commands are unofficial server extensions for debugging\r\n", "only. You may find them useful if you are using telnet as a client.\r\n", "If you are writing a client, you MUST NOT use these commands, since\r\n", "they won't be supported on any other server!\r\n", "\r\n", "D word -- DEFINE * word\r\n", "D database word -- DEFINE database word\r\n", "M word -- MATCH * . word\r\n", "M strategy word -- MATCH * strategy word\r\n", "M database strategy word -- MATCH database strategy word\r\n", "S -- STATUS\r\n", "H -- HELP\r\n", "Q -- QUIT\r\n"] }
7
+
8
+ let(:output){"DEFINE database word -- look up word in database\r\nMATCH database strategy word -- match word in database using strategy\r\nSHOW DB -- list all accessible databases\r\nSHOW DATABASES -- list all accessible databases\r\nSHOW STRAT -- list available matching strategies\r\nSHOW STRATEGIES -- list available matching strategies\r\nSHOW INFO database -- provide information about the database\r\nSHOW SERVER -- provide site-specific information\r\nOPTION MIME -- use MIME headers\r\nCLIENT info -- identify client to server\r\nAUTH user string -- provide authentication information\r\nSTATUS -- display timing information\r\nHELP -- display this help information\r\nQUIT -- terminate connection\r\n\r\nThe following commands are unofficial server extensions for debugging\r\nonly. You may find them useful if you are using telnet as a client.\r\nIf you are writing a client, you MUST NOT use these commands, since\r\nthey won't be supported on any other server!\r\n\r\nD word -- DEFINE * word\r\nD database word -- DEFINE database word\r\nM word -- MATCH * . word\r\nM strategy word -- MATCH * strategy word\r\nM database strategy word -- MATCH database strategy word\r\nS -- STATUS\r\nH -- HELP\r\nQ -- QUIT\r\n"}
9
+
10
+ subject{DictClient::SimpleResponse.new(input)}
11
+
12
+ it 'processes response' do
13
+
14
+ subject.to_s.should == output
15
+
16
+ ["abr1w \"Словарь синонимов Н.Абрамова\"\r\n", "muiswerk \"Dutch monolingual dictionary\"\r\n", "magus \"Новый Большой англо-русский словарь\"\r\n", "meddict \"Медицинский словарь\"\r\n", "mueller24 \"Mueller English-Russian Dictionary\"\r\n", "ozhshv \"Толковый словарь русского языка Ожегова и Шведовой\"\r\n", "dalf \"Толковый словарь живого великорусского языка\"\r\n", "church \"Словарь церковных терминов\"\r\n", "hi127 \"Словарь-указатель по древнерусскому искусству\"\r\n", "ahiezer \"Термины книги «Критика исторического опыта» А.С.Ахиезера\"\r\n", "findict \"Словарь финансовых терминов\"\r\n", "sdict_ru-en \"Russian-English full dictionary\"\r\n", "sdict_fi-ru \"Finnish-Russian dictionary\"\r\n", "geology_en-ru \"Geological English-Russian dictionary\"\r\n", "geology_ru-en \"Geological Russian-English dictionary\"\r\n", "deutsch_ru-de \"Russian-Deutsch dictionary\"\r\n", "deutsch_de-ru \"Deutsch-Russian dictionary\"\r\n", "swedish_ru-sv \"Russian-Swedish dictionary\"\r\n", "swedish_sv-ru \"Swedish-Russian dictionary\"\r\n", "sokrat_ru-en \"sokrat_ruen\"\r\n", "sokrat_en-ru \"sokrat_enru\"\r\n", "korolew_ru-en \"korolew_ru-en\"\r\n", "korolew_en-ru \"korolew_enru\"\r\n", "mech \"mech\"\r\n", "biology \"biology\"\r\n", "idioms \"Русско-английский словарь идиом\"\r\n", "ushakov \"Толковый словарь Ушакова\"\r\n", "ozhegov \"Толковый словарь Ожегова\"\r\n", "brok_and_efr \"Энциклопедический словарь Брокгауза и Ефрона\"\r\n", "teo \"Теософский словарь\"\r\n", "aviation \"Russian abbreviations for aviation\"\r\n", "sc-abbr \"Computer Science Abbreviations\"\r\n", "religion \"История религии\"\r\n", "ethnographic \"Этнографический словарь\"\r\n", "1000pbio \"1000+ biography\"\r\n", "zhelezyaki_abbr \"USSR abbreviations for chips\"\r\n", "zhelezyaki_analogs \"Analogs for USSR chips\"\r\n", "slovnyk_uk-ru \"slovnyk_uk-ru\"\r\n", "slovnyk_uk-pl \"slovnyk_uk-pl\"\r\n", "slovnyk_uk-en \"slovnyk_uk-en\"\r\n", "slovnyk_uk-be \"slovnyk_uk-be\"\r\n", "slovnyk_ru-uk \"slovnyk_ru-uk\"\r\n", "slovnyk_ru-pl \"slovnyk_ru-pl\"\r\n", "slovnyk_ru-en \"slovnyk_ru-en\"\r\n", "slovnyk_ru-be \"slovnyk_ru-be\"\r\n", "slovnyk_pl-uk \"slovnyk_pl-uk\"\r\n", "slovnyk_pl-ru \"slovnyk_pl-ru\"\r\n", "slovnyk_pl-en \"slovnyk_pl-en\"\r\n", "slovnyk_en-uk \"slovnyk_en-uk\"\r\n", "slovnyk_pl-be \"slovnyk_pl-be\"\r\n", "slovnyk_en-ru \"slovnyk_en-ru\"\r\n", "slovnyk_en-pl \"slovnyk_en-pl\"\r\n", "slovnyk_en-be \"slovnyk_en-be\"\r\n", "slovnyk_be-uk \"slovnyk_be-uk\"\r\n", "slovnyk_be-ru \"slovnyk_be-ru\"\r\n", "slovnyk_be-en \"slovnyk_be-en\"\r\n", "slovnyk_be-pl \"slovnyk_be-pl\"\r\n", "beslov \"Большой Энциклопедический Словарь\"\r\n", "ses \"Современный энциклопедический словарь\"\r\n", "mueller7 \"Mueller English-Russian Dictionary\"\r\n", "sinyagin_general_re \"sinyagin_general_re\"\r\n", "sinyagin_general_er \"sinyagin_general_er\"\r\n", "sinyagin_computer \"sinyagin_computer\"\r\n", "sinyagin_business \"sinyagin_business\"\r\n", "sinyagin_alexeymavrin \"sinyagin_alexeymavrin\"\r\n", "sinyagin_abbrev \"sinyagin_abbrev\"\r\n", "smiley \"smiley\"\r\n", "compbe \"English-Belarusian Computer Dictionary\"\r\n", "latrus \"Латинско-русский словарь\"\r\n", "engcom \"The Open English-Russian Computer Dictionary\"\r\n", "komi-rus \"Komi-Russian Dictionary\"\r\n", "estonian_et-ru \"Estonian-Russian dictionary\"\r\n", "foldoc \"The Free On-line Dictionary of Computing (19 Sep 2003)\"\r\n", "Hebrew-Russian \"Hebrew-Russian Dictionary\"\r\n", "Russian-Hebrew \"Russian-Hebrew Dictionary\"\r\n", "hebrusld \"Иврит-русский юридический словарь\"\r\n", "hebrusdi \"Иврит-русский словарь по страхованию\"\r\n", "rushebld \"Русско-ивритский юридический словарь\"\r\n", "rushebdi \"Русско-Ивритский словарь по страхованию\"\r\n", "en-ru \"A collection of English-Russian dictionaries\"\r\n", "ru-en \"A collection of Russian-English dictionaries\"\r\n", "ru-ru \"A collection of Russian monolingual dictionaries\"\r\n", "ru-de \"A collection of Russian-German dictionaries\"\r\n", "ru-pl \"A collection of Russian-Polish dictionaries\"\r\n", "ru-be \"A collection of Russian-Belarusian dictionaries\"\r\n", "ru-uk \"A collection of Russian-Ukrainian dictionaries\"\r\n", "de-ru \"A collection of German-Russian dictionaries\"\r\n", "uk-ru \"A collection of Ukraine-Russian dictionaries\"\r\n", "et-ru \"A collection of Estonian-Russian dictionaries\"\r\n", "fi-ru \"A collection of Finnish-Russian dictionaries\"\r\n", "he-ru \"A collection of Hebrew-Russian dictionaries\"\r\n", "ru-he \"A collection of Russian-Hebrew dictionaries\"\r\n", "mech_nomime \"mech\"\r\n", "mech_mime \"mech\"\r\n"]
17
+
18
+ end
19
+
20
+ end
21
+
22
+
23
+ describe DictClient::KeyValueResponse do
24
+
25
+ let(:input){["abr1w \"Словарь синонимов Н.Абрамова\"\r\n", "muiswerk \"Dutch monolingual dictionary\"\r\n", "magus \"Новый Большой англо-русский словарь\"\r\n", "meddict \"Медицинский словарь\"\r\n", "mueller24 \"Mueller English-Russian Dictionary\"\r\n", "ozhshv \"Толковый словарь русского языка Ожегова и Шведовой\"\r\n", "dalf \"Толковый словарь живого великорусского языка\"\r\n", "church \"Словарь церковных терминов\"\r\n", "hi127 \"Словарь-указатель по древнерусскому искусству\"\r\n", "ahiezer \"Термины книги «Критика исторического опыта» А.С.Ахиезера\"\r\n", "findict \"Словарь финансовых терминов\"\r\n", "sdict_ru-en \"Russian-English full dictionary\"\r\n", "sdict_fi-ru \"Finnish-Russian dictionary\"\r\n", "geology_en-ru \"Geological English-Russian dictionary\"\r\n", "geology_ru-en \"Geological Russian-English dictionary\"\r\n", "deutsch_ru-de \"Russian-Deutsch dictionary\"\r\n", "deutsch_de-ru \"Deutsch-Russian dictionary\"\r\n", "swedish_ru-sv \"Russian-Swedish dictionary\"\r\n", "swedish_sv-ru \"Swedish-Russian dictionary\"\r\n", "sokrat_ru-en \"sokrat_ruen\"\r\n", "sokrat_en-ru \"sokrat_enru\"\r\n", "korolew_ru-en \"korolew_ru-en\"\r\n", "korolew_en-ru \"korolew_enru\"\r\n", "mech \"mech\"\r\n", "biology \"biology\"\r\n", "idioms \"Русско-английский словарь идиом\"\r\n", "ushakov \"Толковый словарь Ушакова\"\r\n", "ozhegov \"Толковый словарь Ожегова\"\r\n", "brok_and_efr \"Энциклопедический словарь Брокгауза и Ефрона\"\r\n", "teo \"Теософский словарь\"\r\n", "aviation \"Russian abbreviations for aviation\"\r\n", "sc-abbr \"Computer Science Abbreviations\"\r\n", "religion \"История религии\"\r\n", "ethnographic \"Этнографический словарь\"\r\n", "1000pbio \"1000+ biography\"\r\n", "zhelezyaki_abbr \"USSR abbreviations for chips\"\r\n", "zhelezyaki_analogs \"Analogs for USSR chips\"\r\n", "slovnyk_uk-ru \"slovnyk_uk-ru\"\r\n", "slovnyk_uk-pl \"slovnyk_uk-pl\"\r\n", "slovnyk_uk-en \"slovnyk_uk-en\"\r\n", "slovnyk_uk-be \"slovnyk_uk-be\"\r\n", "slovnyk_ru-uk \"slovnyk_ru-uk\"\r\n", "slovnyk_ru-pl \"slovnyk_ru-pl\"\r\n", "slovnyk_ru-en \"slovnyk_ru-en\"\r\n", "slovnyk_ru-be \"slovnyk_ru-be\"\r\n", "slovnyk_pl-uk \"slovnyk_pl-uk\"\r\n", "slovnyk_pl-ru \"slovnyk_pl-ru\"\r\n", "slovnyk_pl-en \"slovnyk_pl-en\"\r\n", "slovnyk_en-uk \"slovnyk_en-uk\"\r\n", "slovnyk_pl-be \"slovnyk_pl-be\"\r\n", "slovnyk_en-ru \"slovnyk_en-ru\"\r\n", "slovnyk_en-pl \"slovnyk_en-pl\"\r\n", "slovnyk_en-be \"slovnyk_en-be\"\r\n", "slovnyk_be-uk \"slovnyk_be-uk\"\r\n", "slovnyk_be-ru \"slovnyk_be-ru\"\r\n", "slovnyk_be-en \"slovnyk_be-en\"\r\n", "slovnyk_be-pl \"slovnyk_be-pl\"\r\n", "beslov \"Большой Энциклопедический Словарь\"\r\n", "ses \"Современный энциклопедический словарь\"\r\n", "mueller7 \"Mueller English-Russian Dictionary\"\r\n", "sinyagin_general_re \"sinyagin_general_re\"\r\n", "sinyagin_general_er \"sinyagin_general_er\"\r\n", "sinyagin_computer \"sinyagin_computer\"\r\n", "sinyagin_business \"sinyagin_business\"\r\n", "sinyagin_alexeymavrin \"sinyagin_alexeymavrin\"\r\n", "sinyagin_abbrev \"sinyagin_abbrev\"\r\n", "smiley \"smiley\"\r\n", "compbe \"English-Belarusian Computer Dictionary\"\r\n", "latrus \"Латинско-русский словарь\"\r\n", "engcom \"The Open English-Russian Computer Dictionary\"\r\n", "komi-rus \"Komi-Russian Dictionary\"\r\n", "estonian_et-ru \"Estonian-Russian dictionary\"\r\n", "foldoc \"The Free On-line Dictionary of Computing (19 Sep 2003)\"\r\n", "Hebrew-Russian \"Hebrew-Russian Dictionary\"\r\n", "Russian-Hebrew \"Russian-Hebrew Dictionary\"\r\n", "hebrusld \"Иврит-русский юридический словарь\"\r\n", "hebrusdi \"Иврит-русский словарь по страхованию\"\r\n", "rushebld \"Русско-ивритский юридический словарь\"\r\n", "rushebdi \"Русско-Ивритский словарь по страхованию\"\r\n", "en-ru \"A collection of English-Russian dictionaries\"\r\n", "ru-en \"A collection of Russian-English dictionaries\"\r\n", "ru-ru \"A collection of Russian monolingual dictionaries\"\r\n", "ru-de \"A collection of Russian-German dictionaries\"\r\n", "ru-pl \"A collection of Russian-Polish dictionaries\"\r\n", "ru-be \"A collection of Russian-Belarusian dictionaries\"\r\n", "ru-uk \"A collection of Russian-Ukrainian dictionaries\"\r\n", "de-ru \"A collection of German-Russian dictionaries\"\r\n", "uk-ru \"A collection of Ukraine-Russian dictionaries\"\r\n", "et-ru \"A collection of Estonian-Russian dictionaries\"\r\n", "fi-ru \"A collection of Finnish-Russian dictionaries\"\r\n", "he-ru \"A collection of Hebrew-Russian dictionaries\"\r\n", "ru-he \"A collection of Russian-Hebrew dictionaries\"\r\n", "mech_nomime \"mech\"\r\n", "mech_mime \"mech\"\r\n"] }
26
+
27
+ let(:output){" abr1w Словарь синонимов Н.Абрамова \n muiswerk Dutch monolingual dictionary \n magus Новый Большой англо-русский словарь \n meddict Медицинский словарь \n mueller24 Mueller English-Russian Dictionary \n ozhshv Толковый словарь русского языка Ожегова и Шведовой \n dalf Толковый словарь живого великорусского языка \n church Словарь церковных терминов \n hi127 Словарь-указатель по древнерусскому искусству \n ahiezer Термины книги «Критика исторического опыта» А.С.Ахиезера\n findict Словарь финансовых терминов \n sdict_ru-en Russian-English full dictionary \n sdict_fi-ru Finnish-Russian dictionary \n geology_en-ru Geological English-Russian dictionary \n geology_ru-en Geological Russian-English dictionary \n deutsch_ru-de Russian-Deutsch dictionary \n deutsch_de-ru Deutsch-Russian dictionary \n swedish_ru-sv Russian-Swedish dictionary \n swedish_sv-ru Swedish-Russian dictionary \n sokrat_ru-en sokrat_ruen \n sokrat_en-ru sokrat_enru \n korolew_ru-en korolew_ru-en \n korolew_en-ru korolew_enru \n mech mech \n biology biology \n idioms Русско-английский словарь идиом \n ushakov Толковый словарь Ушакова \n ozhegov Толковый словарь Ожегова \n brok_and_efr Энциклопедический словарь Брокгауза и Ефрона \n teo Теософский словарь \n aviation Russian abbreviations for aviation \n sc-abbr Computer Science Abbreviations \n religion История религии \n ethnographic Этнографический словарь \n 1000pbio 1000+ biography \n zhelezyaki_abbr USSR abbreviations for chips \n zhelezyaki_analogs Analogs for USSR chips \n slovnyk_uk-ru slovnyk_uk-ru \n slovnyk_uk-pl slovnyk_uk-pl \n slovnyk_uk-en slovnyk_uk-en \n slovnyk_uk-be slovnyk_uk-be \n slovnyk_ru-uk slovnyk_ru-uk \n slovnyk_ru-pl slovnyk_ru-pl \n slovnyk_ru-en slovnyk_ru-en \n slovnyk_ru-be slovnyk_ru-be \n slovnyk_pl-uk slovnyk_pl-uk \n slovnyk_pl-ru slovnyk_pl-ru \n slovnyk_pl-en slovnyk_pl-en \n slovnyk_en-uk slovnyk_en-uk \n slovnyk_pl-be slovnyk_pl-be \n slovnyk_en-ru slovnyk_en-ru \n slovnyk_en-pl slovnyk_en-pl \n slovnyk_en-be slovnyk_en-be \n slovnyk_be-uk slovnyk_be-uk \n slovnyk_be-ru slovnyk_be-ru \n slovnyk_be-en slovnyk_be-en \n slovnyk_be-pl slovnyk_be-pl \n beslov Большой Энциклопедический Словарь \n ses Современный энциклопедический словарь \n mueller7 Mueller English-Russian Dictionary \n sinyagin_general_re sinyagin_general_re \n sinyagin_general_er sinyagin_general_er \n sinyagin_computer sinyagin_computer \n sinyagin_business sinyagin_business \nsinyagin_alexeymavrin sinyagin_alexeymavrin \n sinyagin_abbrev sinyagin_abbrev \n smiley smiley \n compbe English-Belarusian Computer Dictionary \n latrus Латинско-русский словарь \n engcom The Open English-Russian Computer Dictionary \n komi-rus Komi-Russian Dictionary \n estonian_et-ru Estonian-Russian dictionary \n foldoc The Free On-line Dictionary of Computing (19 Sep 2003) \n Hebrew-Russian Hebrew-Russian Dictionary \n Russian-Hebrew Russian-Hebrew Dictionary \n hebrusld Иврит-русский юридический словарь \n hebrusdi Иврит-русский словарь по страхованию \n rushebld Русско-ивритский юридический словарь \n rushebdi Русско-Ивритский словарь по страхованию \n en-ru A collection of English-Russian dictionaries \n ru-en A collection of Russian-English dictionaries \n ru-ru A collection of Russian monolingual dictionaries \n ru-de A collection of Russian-German dictionaries \n ru-pl A collection of Russian-Polish dictionaries \n ru-be A collection of Russian-Belarusian dictionaries \n ru-uk A collection of Russian-Ukrainian dictionaries \n de-ru A collection of German-Russian dictionaries \n uk-ru A collection of Ukraine-Russian dictionaries \n et-ru A collection of Estonian-Russian dictionaries \n fi-ru A collection of Finnish-Russian dictionaries \n he-ru A collection of Hebrew-Russian dictionaries \n ru-he A collection of Russian-Hebrew dictionaries \n mech_nomime mech \n mech_mime mech "}
28
+
29
+ subject{DictClient::KeyValueResponse.new(input)}
30
+
31
+ it 'processes response' do
32
+ subject.to_s.should == output
33
+ end
34
+
35
+ it 'provides structured info' do
36
+ subject.to_h.should be_kind_of(Hash)
37
+ end
38
+
39
+ it 'returns the correct list of dbs' do
40
+ subject.to_h.keys.sort.should == ["1000pbio", "Hebrew-Russian", "Russian-Hebrew", "abr1w", "ahiezer", "aviation", "beslov", "biology", "brok_and_efr", "church", "compbe", "dalf", "de-ru", "deutsch_de-ru", "deutsch_ru-de", "en-ru", "engcom", "estonian_et-ru", "et-ru", "ethnographic", "fi-ru", "findict", "foldoc", "geology_en-ru", "geology_ru-en", "he-ru", "hebrusdi", "hebrusld", "hi127", "idioms", "komi-rus", "korolew_en-ru", "korolew_ru-en", "latrus", "magus", "mech", "mech_mime", "mech_nomime", "meddict", "mueller24", "mueller7", "muiswerk", "ozhegov", "ozhshv", "religion", "ru-be", "ru-de", "ru-en", "ru-he", "ru-pl", "ru-ru", "ru-uk", "rushebdi", "rushebld", "sc-abbr", "sdict_fi-ru", "sdict_ru-en", "ses", "sinyagin_abbrev", "sinyagin_alexeymavrin", "sinyagin_business", "sinyagin_computer", "sinyagin_general_er", "sinyagin_general_re", "slovnyk_be-en", "slovnyk_be-pl", "slovnyk_be-ru", "slovnyk_be-uk", "slovnyk_en-be", "slovnyk_en-pl", "slovnyk_en-ru", "slovnyk_en-uk", "slovnyk_pl-be", "slovnyk_pl-en", "slovnyk_pl-ru", "slovnyk_pl-uk", "slovnyk_ru-be", "slovnyk_ru-en", "slovnyk_ru-pl", "slovnyk_ru-uk", "slovnyk_uk-be", "slovnyk_uk-en", "slovnyk_uk-pl", "slovnyk_uk-ru", "smiley", "sokrat_en-ru", "sokrat_ru-en", "swedish_ru-sv", "swedish_sv-ru", "teo", "uk-ru", "ushakov", "zhelezyaki_abbr", "zhelezyaki_analogs"]
41
+ end
42
+
43
+
44
+ end
45
+
46
+
47
+ describe DictClient::WordMatch do
48
+
49
+ let(:input){["magus \"alligator apple\"\r\n", "magus \"american apple\"\r\n", "magus \"apple\"\r\n", "magus \"apple dumpling\"\r\n", "magus \"apple green\"\r\n", "magus \"apple marrow\"\r\n", "magus \"apple pulp\"\r\n", "magus \"apple strudel\"\r\n", "magus \"big apple\"\r\n", "magus \"devils apple\"\r\n", "magus \"jelly apple\"\r\n", "magus \"love apple\"\r\n", "magus \"may apple\"\r\n", "magus \"osage apple\"\r\n", "magus \"paradise apple\"\r\n", "magus \"sorb apple\"\r\n", "magus \"toffee apple\"\r\n", "magus \"wild apple\"\r\n", "mueller24 \"adams apple\"\r\n", "mueller24 \"apple\"\r\n", "mueller24 \"apple dumpling\"\r\n", "mueller24 \"apple sauce\"\r\n", "sokrat_en-ru \"apple\"\r\n", "sokrat_en-ru \"apple blossom\"\r\n", "sokrat_en-ru \"apple of discord\"\r\n", "sokrat_en-ru \"apple orchard\"\r\n", "sokrat_en-ru \"apple tree\"\r\n", "sokrat_en-ru \"crab apple\"\r\n", "sokrat_en-ru \"peel the apple\"\r\n", "sokrat_en-ru \"thorn apple\"\r\n", "korolew_en-ru \"apple\"\r\n", "slovnyk_en-uk \"apple\"\r\n", "slovnyk_en-ru \"apple\"\r\n", "slovnyk_en-pl \"apple\"\r\n", "slovnyk_en-be \"apple\"\r\n", "mueller7 \"adams apple\"\r\n", "mueller7 \"apple\"\r\n", "mueller7 \"apple dumpling\"\r\n", "mueller7 \"apple sauce\"\r\n", "sinyagin_general_er \"apple\"\r\n", "sinyagin_computer \"apple\"\r\n", "foldoc \"apple\"\r\n", "foldoc \"apple attachment unit interface\"\r\n", "foldoc \"apple computer, inc.\"\r\n", "foldoc \"apple ii\"\r\n", "foldoc \"apple macintosh\"\r\n", "foldoc \"apple newton\"\r\n", "foldoc \"apple open collaboration environment\"\r\n", "foldoc \"boycott apple\"\r\n"]}
50
+
51
+ let(:output){" magus alligator apple \n magus american apple \n magus apple \n magus apple dumpling \n magus apple green \n magus apple marrow \n magus apple pulp \n magus apple strudel \n magus big apple \n magus devils apple \n magus jelly apple \n magus love apple \n magus may apple \n magus osage apple \n magus paradise apple \n magus sorb apple \n magus toffee apple \n magus wild apple \n mueller24 adams apple \n mueller24 apple \n mueller24 apple dumpling \n mueller24 apple sauce \n sokrat_en-ru apple \n sokrat_en-ru apple blossom \n sokrat_en-ru apple of discord \n sokrat_en-ru apple orchard \n sokrat_en-ru apple tree \n sokrat_en-ru crab apple \n sokrat_en-ru peel the apple \n sokrat_en-ru thorn apple \n korolew_en-ru apple \n slovnyk_en-uk apple \n slovnyk_en-ru apple \n slovnyk_en-pl apple \n slovnyk_en-be apple \n mueller7 adams apple \n mueller7 apple \n mueller7 apple dumpling \n mueller7 apple sauce \nsinyagin_general_er apple \n sinyagin_computer apple \n foldoc apple \n foldoc apple attachment unit interface \n foldoc apple computer, inc. \n foldoc apple ii \n foldoc apple macintosh \n foldoc apple newton \n foldoc apple open collaboration environment\n foldoc boycott apple "}
52
+
53
+ subject{DictClient::WordMatch.new(input)}
54
+
55
+ it 'processes response' do
56
+ subject.to_s.should == output
57
+ end
58
+
59
+ it 'counts matches' do
60
+ subject.count.should == 49
61
+ end
62
+
63
+ it 'returns the correct list of matches' do
64
+ subject.matches.should be_kind_of(Array)
65
+ subject.matches[0].should be_kind_of(Array)
66
+ subject.matches[0].size.should == 2
67
+
68
+ subject.matches.sort .should == [["foldoc", "apple"], ["foldoc", "apple attachment unit interface"], ["foldoc", "apple computer, inc."], ["foldoc", "apple ii"], ["foldoc", "apple macintosh"], ["foldoc", "apple newton"], ["foldoc", "apple open collaboration environment"], ["foldoc", "boycott apple"], ["korolew_en-ru", "apple"], ["magus", "alligator apple"], ["magus", "american apple"], ["magus", "apple"], ["magus", "apple dumpling"], ["magus", "apple green"], ["magus", "apple marrow"], ["magus", "apple pulp"], ["magus", "apple strudel"], ["magus", "big apple"], ["magus", "devils apple"], ["magus", "jelly apple"], ["magus", "love apple"], ["magus", "may apple"], ["magus", "osage apple"], ["magus", "paradise apple"], ["magus", "sorb apple"], ["magus", "toffee apple"], ["magus", "wild apple"], ["mueller24", "adams apple"], ["mueller24", "apple"], ["mueller24", "apple dumpling"], ["mueller24", "apple sauce"], ["mueller7", "adams apple"], ["mueller7", "apple"], ["mueller7", "apple dumpling"], ["mueller7", "apple sauce"], ["sinyagin_computer", "apple"], ["sinyagin_general_er", "apple"], ["slovnyk_en-be", "apple"], ["slovnyk_en-pl", "apple"], ["slovnyk_en-ru", "apple"], ["slovnyk_en-uk", "apple"], ["sokrat_en-ru", "apple"], ["sokrat_en-ru", "apple blossom"], ["sokrat_en-ru", "apple of discord"], ["sokrat_en-ru", "apple orchard"], ["sokrat_en-ru", "apple tree"], ["sokrat_en-ru", "crab apple"], ["sokrat_en-ru", "peel the apple"], ["sokrat_en-ru", "thorn apple"]]
69
+ end
70
+
71
+
72
+ end
73
+
74
+ describe DictClient::WordDefinitions do
75
+
76
+ let(:input){["151 \"torrent\" magus \"Новый Большой англо-русский словарь\"\r\n", "torrent\r\n", " 1> стремительный поток\r\n", "\t _Ex:\r\n", " a mountain torrent горный поток\r\n", "\t _Ex:\r\n", " torrent mountain-brook стремительный горный ручей\r\n", " 2> поток, река, лавина\r\n", "\t _Ex:\r\n", " engulfed in a torrent of enemy troops захваченный лавиной\r\n", " вражеских войск\r\n", "\t _Ex:\r\n", " there was a torrent of lava (from a volcano) (изверженная\r\n", " вулканом) лава текла рекой\r\n", " 3> поток (слов и т. п.)\r\n", "\t _Ex:\r\n", " torrent of words поток слов\r\n", "\t _Ex:\r\n", " torrent of emotion поток страстей, бурные чувства\r\n", " 4> _pl. ливень\r\n", "\t _Ex:\r\n", " the rain was streaming down in torrents дождь лил как из\r\n", " ведра; разверзлись хляби небесные\r\n", " 5> _геол. сель, силь\r\n", "\r\n", "151 \"torrent\" mueller24 \"Mueller English-Russian Dictionary\"\r\n", "torrent\r\n", " _n.\r\n", " 1: стремительный поток\r\n", " 2: _pl. ливень\r\n", " 3: поток (ругательств и т. п.)\r\n", "\r\n", "151 \"torrent\" sokrat_en-ru \"sokrat_enru\"\r\n", "torrent\r\n", " поток\r\n", "151 \"torrent\" korolew_en-ru \"korolew_enru\"\r\n", "torrent\r\n", " n поток (тж. перен.)\r\n", "151 \"torrent\" slovnyk_en-uk \"slovnyk_en-uk\"\r\n", "TORRENT\r\n", " \"ПОТІК\"\r\n", "151 \"torrent\" slovnyk_en-uk \"slovnyk_en-uk\"\r\n", "TORRENT\r\n", " \"СТРУМІНЬ\"\r\n", "151 \"torrent\" slovnyk_en-ru \"slovnyk_en-ru\"\r\n", "TORRENT\r\n", " \"ПОТОК\"\r\n", "151 \"torrent\" slovnyk_en-ru \"slovnyk_en-ru\"\r\n", "TORRENT\r\n", " \"ПОТЕК\"\r\n", "151 \"torrent\" slovnyk_en-ru \"slovnyk_en-ru\"\r\n", "TORRENT\r\n", " \"СТРУЮ\"\r\n", "151 \"torrent\" slovnyk_en-ru \"slovnyk_en-ru\"\r\n", "TORRENT\r\n", " \"СТРУЯ\"\r\n", "151 \"torrent\" slovnyk_en-pl \"slovnyk_en-pl\"\r\n", "TORRENT\r\n", " POTOK\r\n", "151 \"torrent\" slovnyk_en-be \"slovnyk_en-be\"\r\n", "TORRENT\r\n", " \"СТРУМЕНЬ\"\r\n", "151 \"torrent\" slovnyk_en-be \"slovnyk_en-be\"\r\n", "TORRENT\r\n", " \"ПЛЫНЬ\"\r\n", "151 \"torrent\" mueller7 \"Mueller English-Russian Dictionary\"\r\n", "torrent\r\n", " [ˈtɔrənt] _n.\r\n", " 1: стремительный поток\r\n", " 2: _pl. ливень\r\n", " 3: поток (ругательств и т.п.)\r\n", "\r\n", "151 \"torrent\" sinyagin_general_er \"sinyagin_general_er\"\r\n", "torrent\r\n", " поток (*ALSO*FIG*)\r\n", "\r\n"]}
77
+
78
+ let(:output){"1) magus (Новый Большой англо-русский словарь): torrent\n----------------------------------------------------------------------------\ntorrent\r\n 1> стремительный поток\r\n\t _Ex:\r\n a mountain torrent горный поток\r\n\t _Ex:\r\n torrent mountain-brook стремительный горный ручей\r\n 2> поток, река, лавина\r\n\t _Ex:\r\n engulfed in a torrent of enemy troops захваченный лавиной\r\n вражеских войск\r\n\t _Ex:\r\n there was a torrent of lava (from a volcano) (изверженная\r\n вулканом) лава текла рекой\r\n 3> поток (слов и т. п.)\r\n\t _Ex:\r\n torrent of words поток слов\r\n\t _Ex:\r\n torrent of emotion поток страстей, бурные чувства\r\n 4> _pl. ливень\r\n\t _Ex:\r\n the rain was streaming down in torrents дождь лил как из\r\n ведра; разверзлись хляби небесные\r\n 5> _геол. сель, силь\r\n\r\n----------------------------------------------------------------------------\n2) mueller24 (Mueller English-Russian Dictionary): torrent\n----------------------------------------------------------------------------\ntorrent\r\n _n.\r\n 1: стремительный поток\r\n 2: _pl. ливень\r\n 3: поток (ругательств и т. п.)\r\n\r\n----------------------------------------------------------------------------\n3) sokrat_en-ru (sokrat_enru): torrent\n----------------------------------------------------------------------------\ntorrent\r\n поток\r\n----------------------------------------------------------------------------\n4) korolew_en-ru (korolew_enru): torrent\n----------------------------------------------------------------------------\ntorrent\r\n n поток (тж. перен.)\r\n----------------------------------------------------------------------------\n5) slovnyk_en-uk (slovnyk_en-uk): torrent\n----------------------------------------------------------------------------\nTORRENT\r\n \"ПОТІК\"\r\n----------------------------------------------------------------------------\n6) slovnyk_en-uk (slovnyk_en-uk): torrent\n----------------------------------------------------------------------------\nTORRENT\r\n \"СТРУМІНЬ\"\r\n----------------------------------------------------------------------------\n7) slovnyk_en-ru (slovnyk_en-ru): torrent\n----------------------------------------------------------------------------\nTORRENT\r\n \"ПОТОК\"\r\n----------------------------------------------------------------------------\n8) slovnyk_en-ru (slovnyk_en-ru): torrent\n----------------------------------------------------------------------------\nTORRENT\r\n \"ПОТЕК\"\r\n----------------------------------------------------------------------------\n9) slovnyk_en-ru (slovnyk_en-ru): torrent\n----------------------------------------------------------------------------\nTORRENT\r\n \"СТРУЮ\"\r\n----------------------------------------------------------------------------\n10) slovnyk_en-ru (slovnyk_en-ru): torrent\n----------------------------------------------------------------------------\nTORRENT\r\n \"СТРУЯ\"\r\n----------------------------------------------------------------------------\n11) slovnyk_en-pl (slovnyk_en-pl): torrent\n----------------------------------------------------------------------------\nTORRENT\r\n POTOK\r\n----------------------------------------------------------------------------\n12) slovnyk_en-be (slovnyk_en-be): torrent\n----------------------------------------------------------------------------\nTORRENT\r\n \"СТРУМЕНЬ\"\r\n----------------------------------------------------------------------------\n13) slovnyk_en-be (slovnyk_en-be): torrent\n----------------------------------------------------------------------------\nTORRENT\r\n \"ПЛЫНЬ\"\r\n----------------------------------------------------------------------------\n14) mueller7 (Mueller English-Russian Dictionary): torrent\n----------------------------------------------------------------------------\ntorrent\r\n [ˈtɔrənt] _n.\r\n 1: стремительный поток\r\n 2: _pl. ливень\r\n 3: поток (ругательств и т.п.)\r\n\r\n----------------------------------------------------------------------------\n15) sinyagin_general_er (sinyagin_general_er): torrent\n----------------------------------------------------------------------------\ntorrent\r\n поток (*ALSO*FIG*)\r\n\r\n----------------------------------------------------------------------------\n"}
79
+
80
+ subject{DictClient::WordDefinitions.new(input)}
81
+
82
+ it 'processes response' do
83
+ subject.to_s.should == output
84
+ end
85
+
86
+ it 'counts definitions' do
87
+ subject.count.should == 15
88
+ end
89
+
90
+ it 'returns the correct list of definitions' do
91
+ subject.definitions.should be_kind_of(Array)
92
+ subject.definitions[0].should be_kind_of(DictClient::WordDefinitions::WordDefinition)
93
+
94
+ subject.definitions[0].word.should == "torrent"
95
+ subject.definitions[0].dictionary_name.should == "magus"
96
+ subject.definitions[0].dictionary_description.should == "Новый Большой англо-русский словарь"
97
+ subject.definitions[0].definition.should == "torrent\r\n 1> стремительный поток\r\n\t _Ex:\r\n a mountain torrent горный поток\r\n\t _Ex:\r\n torrent mountain-brook стремительный горный ручей\r\n 2> поток, река, лавина\r\n\t _Ex:\r\n engulfed in a torrent of enemy troops захваченный лавиной\r\n вражеских войск\r\n\t _Ex:\r\n there was a torrent of lava (from a volcano) (изверженная\r\n вулканом) лава текла рекой\r\n 3> поток (слов и т. п.)\r\n\t _Ex:\r\n torrent of words поток слов\r\n\t _Ex:\r\n torrent of emotion поток страстей, бурные чувства\r\n 4> _pl. ливень\r\n\t _Ex:\r\n the rain was streaming down in torrents дождь лил как из\r\n ведра; разверзлись хляби небесные\r\n 5> _геол. сель, силь\r\n\r\n"
98
+ end
99
+ end
@@ -0,0 +1,83 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'dict_client'
4
+
5
+ class MockedDictdServerSocket
6
+
7
+ attr_reader :incoming_commands
8
+
9
+ SHOW_DB_RESPONSE = [
10
+ %!110 94 databases present\n!,
11
+ %!abr1w "Словарь синонимов Н.Абрамова"\n!,
12
+ %!muiswerk "Dutch monolingual dictionary"\n!,
13
+ %!magus "Новый Большой англо-русский словарь"\n!,
14
+ %!he-ru "A collection of Hebrew-Russian dictionaries"\n!,
15
+ %!ru-he "A collection of Russian-Hebrew dictionaries"\n!,
16
+ %!mech_nomime "mech"\n!,
17
+ %!mech_mime "mech"\n!,
18
+ %!.\r\n!,
19
+ %!250 ok\n!
20
+ ]
21
+
22
+ APPLE_DEFINITIONS = [
23
+ %!150 6 definitions retrieved\r\n!,
24
+ %!151 "apple" slovnyk_en-uk "slovnyk_en-uk"\r\n!,
25
+ %!APPLE\r\n!,
26
+ %!"ЯБЛУКО"\r\n!,
27
+ %!.\r\n!,
28
+ %!151 "apple" slovnyk_en-ru "slovnyk_en-ru"\r\n!,
29
+ %!APPLE\r\n!,
30
+ %!"ЯБЛОНЕВЫЙ"\r\n!,
31
+ %!.\r\n!,
32
+ %!151 "apple" slovnyk_en-pl "slovnyk_en-pl"\r\n!,
33
+ %!APPLE\r\n!,
34
+ %!"JABŁKO"\r\n!,
35
+ %!.\r\n!,
36
+ %!151 "apple" slovnyk_en-be "slovnyk_en-be"\r\n!,
37
+ %!APPLE\r\n!,
38
+ %!"ЯБЛЫК"\r\n!,
39
+ %!.\r\n!,
40
+ %!151 "apple" slovnyk_en-be "slovnyk_en-be"\r\n!,
41
+ %!APPLE\r\n!,
42
+ %!"ЯБЛЫКА"\r\n!,
43
+ %!.\r\n!,
44
+ %!151 "apple" sinyagin_general_er "sinyagin_general_er"\r\n!,
45
+ %!apple\r\n!,
46
+ %!яблоко\r\n!,
47
+ %!.\r\n!,
48
+ %!250 ok [d/m/c = 17/0/396; 0.000r 0.000u 0.000s]\r\n!
49
+ ]
50
+
51
+
52
+ def initialize
53
+ @incoming_commands = []
54
+ @response = "220 \r\n"
55
+ end
56
+
57
+ def readline
58
+ if @response_queue && ! @response_queue.empty?
59
+ @response_queue.shift
60
+ else
61
+ @response
62
+ end
63
+ end
64
+
65
+ def close
66
+ true
67
+ end
68
+
69
+ def write command
70
+ # puts "--- received command #{command}"
71
+ @incoming_commands << command
72
+ case command
73
+ when /^client /
74
+ @response = "250 \r\n"
75
+ when /^show db/
76
+ @response_queue = SHOW_DB_RESPONSE.clone
77
+ when /^define \* "apple"/
78
+
79
+ @response_queue = APPLE_DEFINITIONS.clone
80
+ end
81
+
82
+ end
83
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dict_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dave Pearson
9
+ - Yuri Leikind
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-07-25 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rspec
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: The Dictionary Server Protocol (DICT) is a TCP transaction based query/response
48
+ protocol that allows a client to access dictionary definitions from a set of natural
49
+ language dictionary databases. See RFC 2229 for details. http://tools.ietf.org/html/rfc2229
50
+ email: yuri.leikind@gmail.com
51
+ executables:
52
+ - dict_client
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - .gitignore
57
+ - .rspec
58
+ - COPYING
59
+ - Gemfile
60
+ - README.md
61
+ - Rakefile
62
+ - bin/dict_client
63
+ - dict_client.gemspec
64
+ - lib/dict_client.rb
65
+ - lib/dict_client/client.rb
66
+ - lib/dict_client/readers.rb
67
+ - lib/dict_client/responses.rb
68
+ - spec/client_spec.rb
69
+ - spec/dict_client_spec.rb
70
+ - spec/readers_spec.rb
71
+ - spec/responses_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: https://github.com/leikind/dict_client
74
+ licenses: []
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.23
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: A simple client side DICT library and executable
97
+ test_files:
98
+ - spec/client_spec.rb
99
+ - spec/dict_client_spec.rb
100
+ - spec/readers_spec.rb
101
+ - spec/responses_spec.rb
102
+ - spec/spec_helper.rb