tureng-cli 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0b15f203738fb29dea3093f534e6e4068063f977
4
+ data.tar.gz: 2cdcca7c265abdb1bee90bd5137f8e5454dc78c6
5
+ SHA512:
6
+ metadata.gz: b143d5e6d3868fe8f507fe682dd090d0a3c86b57bc2fea3f4fad6725b0dc46531a1dae94ba377a91b29879e37839ae05f1d8315c42e55c3edd96dd2775e6b737
7
+ data.tar.gz: 94c0685f6441e78dea0a3d4a38959b2aaa62192cdfdcc9f8b4738547b662f6536288636be44e6eba200e306d06bb8139e3747abdbd508fcce15c8d84ec8cec22
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ results.html
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'nokogiri', '1.6.4.1'
5
+ gem 'text-table', '1.2.3'
data/README.md ADDED
@@ -0,0 +1,126 @@
1
+ ## TURENG-CLI
2
+
3
+ msdundar'ın [tureng betiği](https://github.com/msdundar/tureng)'ne GLI gem'i kullanarak command line arayüzü sağlamaktadır.
4
+
5
+ ## Kurulum ve Kullanım
6
+
7
+ Henüz program ruby gem'ine çevrilmediğinden kaynaktan klonlayıp kullanabilirsiniz.
8
+
9
+ ```
10
+ $ git clone https://github.com/alienaut/tureng
11
+ $ cd tureng
12
+ $ bundle install
13
+ ```
14
+
15
+ İnglizceden, türkçeye çeviri yapmak için:
16
+
17
+ ```
18
+ $ bundle exec bin/tureng en ruby
19
+ O====O==============O=========O=========================================O
20
+ | ## | Category | English | Turkish |
21
+ O====O==============O=========O=========================================O
22
+ | 1 | Common Usage | ruby | yakut |
23
+ | 2 | General | ruby | bir kadın ismi |
24
+ | 3 | General | ruby | yakut rengi |
25
+ | 4 | General | ruby | lal |
26
+ | 5 | General | ruby | kırmızı şarap |
27
+ | 6 | General | ruby | kırmızı |
28
+ | 7 | Technical | ruby | yakut |
29
+ | 8 | Technical | ruby | koyu kırmızı cam |
30
+ | 9 | Mining | ruby | yakut |
31
+ | 10 | Places | ruby | güney carolina eyaletinde yerleşim yeri |
32
+ | 11 | Places | ruby | wisconsin eyaletinde yerleşim yeri |
33
+ O====O==============O=========O=========================================O
34
+
35
+ ```
36
+
37
+ Türkçeden, ingilizceye çeviri yapmak için:
38
+
39
+ ```
40
+ $ bundle exec bin/tureng tr yakut
41
+ O====O==============O=========O===============O
42
+ | ## | Category | Turkish | English |
43
+ O====O==============O=========O===============O
44
+ | 1 | Common Usage | yakut | ruby |
45
+ | 2 | General | yakut | oriental ruby |
46
+ | 3 | General | yakut | carbuncle |
47
+ | 4 | General | yakut | true ruby |
48
+ | 5 | General | yakut | vermeil |
49
+ | 6 | Technical | yakut | ruby |
50
+ | 7 | Mining | yakut | ruby |
51
+ O====O==============O=========O===============O
52
+ ```
53
+
54
+ Listelenen çevirileri sınırlamak için:
55
+
56
+ ```
57
+ $ bundle exec bin/tureng -l 5 en ruby
58
+ O====O==============O=========O================O
59
+ | ## | Category | English | Turkish |
60
+ O====O==============O=========O================O
61
+ | 1 | Common Usage | ruby | yakut |
62
+ | 2 | General | ruby | bir kadın ismi |
63
+ | 3 | General | ruby | yakut rengi |
64
+ | 4 | General | ruby | lal |
65
+ | 5 | General | ruby | kırmızı şarap |
66
+ O====O==============O=========O================O
67
+ ```
68
+
69
+ Diğer terimler tablosunu görüntülemek için:
70
+
71
+ ```
72
+ $ bundle exec bin/tureng -f en ruby
73
+ O====O===========O==================O========================O
74
+ | ## | Category | English | Turkish |
75
+ O====O===========O==================O========================O
76
+ | 1 | General | oriental ruby | yakut |
77
+ | 2 | General | true ruby | yakut |
78
+ | 3 | Idioms | as red as a ruby | kıpkırmızı |
79
+ | 4 | Idioms | red as a ruby | kıpkırmızı |
80
+ | 5 | Technical | balas ruby | açık pembe yakut |
81
+ | 6 | Technical | balas ruby | balas yakutu |
82
+ | 7 | Technical | balas ruby | lal yakut |
83
+ | 8 | Technical | cape ruby | capetown yakutu |
84
+ | 9 | Technical | flash ruby | renkli çubuk |
85
+ | 10 | Technical | flash ruby | rubi |
86
+ | 11 | Technical | pot ruby | pota rubisi |
87
+ | 12 | Technical | pot ruby | pota yakutu |
88
+ | 13 | Technical | red ruby | kırmızı yakut |
89
+ | 14 | Technical | ruby alumina | kızıl alumina |
90
+ | 15 | Technical | ruby glass | yakut camı |
91
+ | 16 | Technical | ruby laser | ruby (yakut) lazeri |
92
+ | 17 | Technical | ruby lustre | koyu kırmızı parlaklık |
93
+ | 18 | Technical | ruby silver | yakut gümüşü |
94
+ | 19 | Technical | ruby spinel | yakut spineli |
95
+ | 20 | Technical | ruby spinel | kaba yakut |
96
+ | 21 | Computer | ruby last name | soyadı söyleyiş biçimi |
97
+ | 22 | Computer | ruby text | söyleniş metni |
98
+ | 23 | Computer | ruby-first-name | ruby-adı |
99
+ | 24 | Geology | ruby silver | pirargirit |
100
+ O====O===========O==================O========================O
101
+
102
+ ```
103
+
104
+ Yardım ve mevcut komutları görüntülemek için:
105
+
106
+ ```
107
+ $ bundle exec bin/tureng --help
108
+ ```
109
+
110
+ ## Bilinen Hatalar
111
+
112
+ İngilizce bir kelilme türkçe olarak arandığında hata veriyor:
113
+
114
+ ```
115
+ $ bundle exec bin/tureng tr ruby
116
+ error: undefined method `css' for nil:NilClass
117
+ ```
118
+
119
+ ## Yapılacaklar
120
+
121
+ * Proje ruby gem'ine çevirelerek kurulum kolaylaştırılacak.
122
+ * İngilizce Readme dosyası hazırlanacak.
123
+
124
+ ## Uyarı
125
+
126
+ Tüm kelimeler ve kelimelerin anlamları [tureng sözlükten](http://tureng.com/) çekilmektedir ve tamamı tureng sözlük veritabanlarında bulunmaktadır. Bu uygulama yalnızca konsol ortamından tureng'e erişmek isteyenlere yardımcı olmak için hazırlanmıştır. Görüntülediğiniz tüm içeriklerin yasal hakları vb. tureng'e aittir.
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+ require 'rdoc/task'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+ Rake::RDocTask.new do |rd|
8
+ rd.main = "README.rdoc"
9
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
10
+ rd.title = 'Your application title'
11
+ end
12
+
13
+ spec = eval(File.read('tureng.gemspec'))
14
+
15
+ Gem::PackageTask.new(spec) do |pkg|
16
+ end
17
+ CUKE_RESULTS = 'results.html'
18
+ CLEAN << CUKE_RESULTS
19
+ desc 'Run features'
20
+ Cucumber::Rake::Task.new(:features) do |t|
21
+ opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
22
+ opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
23
+ t.cucumber_opts = opts
24
+ t.fork = false
25
+ end
26
+
27
+ desc 'Run features tagged as work-in-progress (@wip)'
28
+ Cucumber::Rake::Task.new('features:wip') do |t|
29
+ tag_opts = ' --tags ~@pending'
30
+ tag_opts = ' --tags @wip'
31
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
32
+ t.fork = false
33
+ end
34
+
35
+ task :cucumber => :features
36
+ task 'cucumber:wip' => 'features:wip'
37
+ task :wip => 'features:wip'
38
+ require 'rake/testtask'
39
+ Rake::TestTask.new do |t|
40
+ t.libs << "test"
41
+ t.test_files = FileList['test/*_test.rb']
42
+ end
43
+
44
+ task :default => [:test,:features]
data/bin/tureng ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'tureng'
4
+
5
+ # begin # XXX: Remove this begin/rescue before distributing your app
6
+ # rescue LoadError
7
+ # STDERR.puts "In development, you need to use `bundle exec bin/tureng` to run your app"
8
+ # STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
9
+ # STDERR.puts "Feel free to remove this message from bin/tureng now"
10
+ # exit 64
11
+ # end
12
+
13
+ include GLI::App
14
+ include Tureng
15
+
16
+ program_desc 'Describe your application here'
17
+
18
+ version Tureng::VERSION
19
+
20
+ desc 'Define limit of translation to be shown'
21
+ flag [:l, :limit], default_value: nil
22
+
23
+ desc 'Search translation in "other terms" table'
24
+ switch [:f, :full]
25
+
26
+ pre do |global,command,options,args|
27
+ # Pre logic here
28
+ # Return true to proceed; false to abort and not call the
29
+ # chosen command
30
+ # Use skips_pre before a command to skip this block
31
+ # on that command only
32
+ true
33
+ end
34
+
35
+ desc 'Translates English word to Turkish'
36
+ command :en do |c|
37
+ c.action do |global_options, options, args|
38
+ settings = {}
39
+ settings[:language_code] = :en
40
+ settings[:limit] = global_options[:limit].to_i if global_options[:limit]
41
+ settings[:table_type] = 'full' if global_options[:full]
42
+ Translator.new(args.first, settings).draw_table
43
+ end
44
+ end
45
+
46
+ desc 'Translate Turkish word to English'
47
+ command :tr do |c|
48
+ c.action do |global_options, options, args|
49
+ settings = {}
50
+ settings[:language_code] = :tr
51
+ settings[:limit] = global_options[:limit].to_i if global_options[:limit]
52
+ settings[:table_type] = 'full' if global_options[:f]
53
+ Translator.new(args.first, settings).draw_table
54
+ end
55
+ end
56
+
57
+ post do |global,command,options,args|
58
+ # Post logic here
59
+ # Use skips_post before a command to skip this
60
+ # block on that command only
61
+ end
62
+
63
+ on_error do |exception|
64
+ # Error logic here
65
+ # return false to skip default error handling
66
+ true
67
+ end
68
+
69
+ exit run(ARGV)
@@ -0,0 +1,6 @@
1
+ When /^I get help for "([^"]*)"$/ do |app_name|
2
+ @app_name = app_name
3
+ step %(I run `#{app_name} help`)
4
+ end
5
+
6
+ # Add more step definitions here
@@ -0,0 +1,15 @@
1
+ require 'aruba/cucumber'
2
+
3
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
4
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
5
+
6
+ Before do
7
+ # Using "announce" causes massive warnings on 1.9.2
8
+ @puts = true
9
+ @original_rubylib = ENV['RUBYLIB']
10
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
11
+ end
12
+
13
+ After do
14
+ ENV['RUBYLIB'] = @original_rubylib
15
+ end
@@ -0,0 +1,8 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "tureng"
8
+ Then the exit status should be 0
data/lib/tureng.rb ADDED
@@ -0,0 +1,88 @@
1
+ # Authors:
2
+ # Mustafa Serhat DÜNDAR <msdundars@gmail.com>
3
+ # Yusuf YALIM <yusufyalim@gmail.com>
4
+
5
+ require 'tureng/version.rb'
6
+ require 'nokogiri'
7
+ require 'open-uri'
8
+ require 'text-table'
9
+
10
+ module Tureng
11
+ BASE_URL = 'http://tureng.com/'
12
+ SEARCH_URL = BASE_URL + 'search/'
13
+
14
+ class Translator
15
+ attr_reader :word, :limit, :language_code, :table_type, :table, :status,
16
+ :table_tag, :response
17
+
18
+ def initialize(word, settings = {})
19
+ @word = word
20
+ @limit = settings[:limit]
21
+ @language_code = settings[:language_code] || :en
22
+ @table_type = settings[:table_type] || ''
23
+ @table = Text::Table.new(
24
+ horizontal_padding: 1,
25
+ vertical_boundary: '=',
26
+ horizontal_boundary: '|',
27
+ boundary_intersection: 'O'
28
+ )
29
+ @table_id = set_table_id
30
+ @response = get_response
31
+ @status = @response.css('h1')[1].text.strip
32
+ @table_tag = parse_table_from_response
33
+ end
34
+
35
+ def set_table_id
36
+ # sets table id by word language and
37
+ language = { en: 'english', tr: 'turkish' }
38
+ "#{language[language_code]}#{table_type.capitalize}ResultsTable"
39
+ end
40
+
41
+ def get_response
42
+ Nokogiri::HTML(open(SEARCH_URL + word), nil, 'utf-8')
43
+ end
44
+
45
+ def parse_table_from_response
46
+ response.css("table[id='#{@table_id}']")
47
+ end
48
+
49
+ def fill_table
50
+ # parse tr tags
51
+ tr_tags = table_tag.css('tr')
52
+
53
+ # remove heading from tr_tags and save it to another variable
54
+ headings = tr_tags.shift.css('th').map(&:text)
55
+
56
+ # add headings to table as "##, Category, word language, translation
57
+ # language".
58
+ table.head = headings.values_at(1, 3, 4).unshift('##')
59
+
60
+ # add translation to table
61
+ tr_tags.each_with_index do |row, index|
62
+ # add line number, category, word and translation to table
63
+ table.rows << row.css('td').map(&:text).values_at(0, 1, 3, 4)
64
+ # end loop if limit is set and index greater than or equal to limit
65
+ break if limit && index >= (limit - 1)
66
+ end
67
+ end
68
+
69
+ def get_suggestions
70
+ table.head = ['Öneriler']
71
+ table.rows = @response.css('li a').map(&:text)
72
+ end
73
+
74
+ def draw_table
75
+ if status == "Did you mean that?"
76
+ puts status
77
+ get_suggestions
78
+ elsif status == "Term not found"
79
+ puts status
80
+ return nil
81
+ else
82
+ fill_table
83
+ end
84
+
85
+ puts table.to_s
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,3 @@
1
+ module Tureng
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class DefaultTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_the_truth
12
+ assert true
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+
3
+ # Add test libraries you want to use here, e.g. mocha
4
+
5
+ class Test::Unit::TestCase
6
+
7
+ # Add global extensions to the test case class here
8
+
9
+ end
data/tureng.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # Ensure we require the local version and not one we might have installed already
2
+ require File.join([File.dirname(__FILE__),'lib','tureng','version.rb'])
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'tureng-cli'
5
+ s.version = Tureng::VERSION
6
+ s.author = 'Your Name Here'
7
+ s.email = 'your@email.address.com'
8
+ s.homepage = 'http://your.website.com'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = 'A description of your project'
11
+ s.files = `git ls-files`.split("
12
+ ")
13
+ s.require_paths << 'lib'
14
+ s.has_rdoc = true
15
+ s.extra_rdoc_files = []
16
+ s.rdoc_options << '--title' << 'tureng' << '--main' << 'README.rdoc' << '-ri'
17
+ s.bindir = 'bin'
18
+ s.executables << 'tureng'
19
+ s.add_development_dependency('rake')
20
+ s.add_development_dependency('rdoc')
21
+ s.add_development_dependency('aruba')
22
+ s.add_development_dependency('noko-giri')
23
+ s.add_development_dependency('text-table')
24
+ s.add_runtime_dependency('gli','2.12.2')
25
+ end
data/tureng.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = tureng
2
+
3
+ Generate this with
4
+ tureng rdoc
5
+ After you have described your command line interface
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tureng-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Your Name Here
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: noko-giri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: text-table
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: gli
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 2.12.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 2.12.2
97
+ description:
98
+ email: your@email.address.com
99
+ executables:
100
+ - tureng
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - README.md
107
+ - Rakefile
108
+ - bin/tureng
109
+ - features/step_definitions/tureng_steps.rb
110
+ - features/support/env.rb
111
+ - features/tureng.feature
112
+ - lib/tureng.rb
113
+ - lib/tureng/version.rb
114
+ - test/default_test.rb
115
+ - test/test_helper.rb
116
+ - tureng.gemspec
117
+ - tureng.rdoc
118
+ homepage: http://your.website.com
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options:
123
+ - "--title"
124
+ - tureng
125
+ - "--main"
126
+ - README.rdoc
127
+ - "-ri"
128
+ require_paths:
129
+ - lib
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.2.2
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A description of your project
147
+ test_files: []