lingvo 0.0.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 151c38291271ca86091ba8427695aedbb5dc9d71
4
+ data.tar.gz: a1761229c5b0aa0d66dd6cc99ff075d55ea2fcd8
5
+ SHA512:
6
+ metadata.gz: 00eb0bc2db5822cf2776b44d087aa7e72aaaedd5c5439d04cd06959a0e85d00397c339ad1cd059cf21f169a2c7d522ad210c5b42038ebbeb18a5d91bb0eecd51
7
+ data.tar.gz: 8e237c6192e08142dffcbabf5687a22dad6ea1bfc0280e2fcd94b92f59ab64a81ba00a16e80b5f42985fca50d79ac2d16f9257d41d6fa77ca65a67e9898cb2cf
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lingvo.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Igor G
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Lingvo
2
+
3
+ Lingvo - easy helper in learning english words
4
+
5
+ ## Installation
6
+
7
+ $ gem install lingvo
8
+
9
+ ## Usage
10
+
11
+ Options:
12
+
13
+ > --parse file - parse lingovleo HTML file with words
14
+
15
+ > --rand count - show 'n' random records
16
+
17
+ > --nitify - send show word - translation with your notification
18
+
19
+ > --gui - show words in simpe window
20
+
21
+ > key: n - show next word
22
+
23
+ > q - close window
24
+
25
+ > --size - show words count
26
+
27
+ > -h - show this help
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'lingvo'
4
+
5
+ module Lingvo
6
+ module Console
7
+ case ARGV[0]
8
+ when '--parse' then Command.parse ARGV[1]
9
+ when '--rand' then Command.rand ARGV[1]
10
+ when '--size' then Command.size
11
+ when '--notify'then Command.notify
12
+ when '--gui'then Command.gui
13
+ when '-h' then Command.help
14
+
15
+ else
16
+ Command.help
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ require "lingvo/version"
2
+
3
+ require 'lingvo/config/config'
4
+
5
+ require 'lingvo/console/command'
6
+ require 'lingvo/parsers/lingualeo_parser'
7
+
8
+ require 'lingvo/db/connection'
9
+ require 'lingvo/models/english'
10
+
11
+ require 'lingvo/gui/widget'
12
+ require 'lingvo/gui/notify'
@@ -0,0 +1,49 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+
4
+ module Lingvo
5
+ module Config
6
+ class << self
7
+ attr_accessor :notify, :gui
8
+ end
9
+
10
+ LINGVO_DIR = File.expand_path('../..', __FILE__)
11
+
12
+ DEFAULT_CONFIG = "#{LINGVO_DIR}/config/default.yaml"
13
+ DEFAULT_IMG = "#{LINGVO_DIR}/gui/img/eng.png"
14
+
15
+ BASE_DIR = File.join Dir.home, '.lingvo'
16
+ DB_FILE = File.join BASE_DIR, 'english_words.sqlite3'
17
+ CUSTOM_CONFIG = File.join BASE_DIR, 'config.yaml'
18
+
19
+ unless File.exists? BASE_DIR
20
+ FileUtils.mkdir BASE_DIR, mode: 0755
21
+ end
22
+
23
+ unless File.exists? DB_FILE
24
+ FileUtils.touch DB_FILE
25
+ FileUtils.chmod 0755, DB_FILE
26
+ end
27
+
28
+ unless File.exists? CUSTOM_CONFIG
29
+ FileUtils.cp DEFAULT_CONFIG, CUSTOM_CONFIG
30
+ FileUtils.chmod 0755, CUSTOM_CONFIG
31
+ end
32
+
33
+ default_config = YAML.load_file DEFAULT_CONFIG
34
+ custom_config = YAML.load_file CUSTOM_CONFIG
35
+
36
+ default_config['gui']['image'] = DEFAULT_IMG
37
+ default_config['notify']['image'] = DEFAULT_IMG
38
+
39
+ @gui = {}
40
+ default_config['gui'].map do |key, val|
41
+ @gui[key.to_sym] = custom_config['gui'][key] || val
42
+ end
43
+
44
+ @notify = {}
45
+ default_config['notify'].map do |key, val|
46
+ @notify[key.to_sym] = custom_config['notify'][key] || val
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+ notify:
2
+ timeout: 15000 # 15000ms show notifcatin
3
+ twmnc_bg: 'black' # background for twmnc
4
+ twmnc_fg: 'orange' # foreground for twmnc
5
+ image: # default image (eng_flag), '' - without image or full path
6
+ first: 'eng' # or 'ru'
7
+ prefix: '' # start notification
8
+ separate: ' - ' # separate words
9
+ sufix: '' # end notification
10
+
11
+ gui:
12
+ image: # default image (eng_flag), '' - without image or full path
13
+ image_size_x: 75
14
+ image_size_y: 100
15
+ bg: 'black' # bg window color
16
+ margin: 10 # window margin
17
+ eng_fg: 'white' # foreground words color
18
+ eng_size: 22 # word font size in px
19
+ ru_fg: 'gray'
20
+ ru_size: 20
21
+ transcr: 'on'
22
+ transcr_fg: 'red'
23
+ transcr_size: 18
@@ -0,0 +1,77 @@
1
+ module Lingvo
2
+ module Console
3
+ HELP = """
4
+ Lingvo #{VERSION}
5
+
6
+ Options:
7
+ --parse file - parse lingovleo HTML file with words
8
+ --rand count - show 'n' random records
9
+ --nitify - send show word - translation with your notification
10
+ --gui - show words in simpe window
11
+ key: n - show next word
12
+ q - close window
13
+
14
+ --size - show words count
15
+ -h - show this help
16
+
17
+ """
18
+
19
+ class << self
20
+ def which(cmd)
21
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
22
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
23
+ exts.each do |ext|
24
+ exe = File.join(path, "#{cmd}#{ext}")
25
+ return exe if File.executable? exe
26
+ end
27
+ end
28
+ nil
29
+ end
30
+
31
+ def no_word
32
+ puts "You don't have any words"
33
+ exit
34
+ end
35
+ end
36
+
37
+ class Command
38
+ class << self
39
+ def parse(path)
40
+ if File.exists? path
41
+ parser = Parsers::Lingualeo.new path
42
+ Models::English.create parser.words
43
+ size
44
+ else
45
+ puts "File not found!"
46
+ help
47
+ end
48
+ end
49
+
50
+ def rand(count)
51
+ count = (count || 1).to_i
52
+
53
+ words = Models::English.rand count
54
+ words.each do |word|
55
+ puts "#{word.eng} - #{word.transcr} - #{word.ru}"
56
+ end
57
+ end
58
+
59
+ def size
60
+ puts "You have #{Models::English.count} words"
61
+ end
62
+
63
+ def notify
64
+ GUI::Notify.run
65
+ end
66
+
67
+ def gui
68
+ GUI::Simple.run
69
+ end
70
+
71
+ def help
72
+ puts HELP
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,14 @@
1
+ require 'active_record'
2
+
3
+ module Lingvo
4
+ module DB
5
+ module Connection
6
+ ActiveRecord::Base.establish_connection(
7
+ adapter: "sqlite3",
8
+ database: Config::DB_FILE
9
+ )
10
+
11
+ ActiveRecord::Migrator.migrate "#{Config::LINGVO_DIR}/db/migration/"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ class English < ActiveRecord::Migration
2
+ def up
3
+ create_table :english do |t|
4
+ t.column :eng, :string, :null => false
5
+ t.column :ru, :string, :null => false
6
+ t.column :transcr, :string
7
+ end
8
+ end
9
+
10
+ def down
11
+ drop_table :english
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ module Lingvo
2
+ module GUI
3
+ class Notify
4
+ class << self
5
+ def show(eng, ru)
6
+ conf = Config.notify
7
+
8
+ first = conf[:prefix] + (conf[:first] == 'eng' ? eng : ru)
9
+ second = conf[:separate] + (conf[:first] == 'eng' ? ru : eng) + conf[:sufix]
10
+
11
+ if Console.which('twmnc')
12
+ command = 'twmnc'
13
+ command += " -t '#{first}'"
14
+ command += " -c '#{second}'"
15
+ command += " --bg '#{conf[:twmnc_bg]}'"
16
+ command += " --fg '#{conf[:twmnc_fg]}'"
17
+ command += " -i '#{conf[:image]}'"
18
+ command += " -d #{conf[:timeout].to_i}"
19
+
20
+ elsif Console.which('notify-send')
21
+ command = 'notify-send -u normal'
22
+ command += " -t #{conf[:timeout].to_i}"
23
+ command += " -i '#{conf[:image]}'"
24
+ command += " '#{first}#{second}'"
25
+
26
+ else
27
+ puts 'Please install notify-send or twmn(twmnc) notification system'
28
+ exit
29
+ end
30
+
31
+ system command
32
+ end
33
+
34
+ def run
35
+ word = Lingvo::Models::English.rand(1).first
36
+ Console.no_word if word.nil?
37
+ show word.eng, word.ru
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,74 @@
1
+ require 'Qt4'
2
+
3
+ module Lingvo
4
+ module GUI
5
+ class Widget < Qt::Widget
6
+ slots :close, :update
7
+
8
+ def initialize(parent = nil)
9
+ super
10
+ @conf = Config.gui
11
+ @conf[:size_for_image] = 0
12
+
13
+ setStyleSheet("* { background: #{@conf[:bg]}; margin: #{@conf[:margin]}px }");
14
+ Qt::Shortcut.new Qt::KeySequence.new(Qt::Key_Q.to_i), self, SLOT(:close)
15
+ Qt::Shortcut.new Qt::KeySequence.new(Qt::Key_N.to_i), self, SLOT(:update)
16
+
17
+ if @conf[:image].present?
18
+ pixmap = Qt::Pixmap.new(@conf[:image]).scaled(@conf[:image_size_y], @conf[:image_size_x])
19
+ Qt::Label.new('',self).setPixmap pixmap
20
+ @conf[:size_for_image] = @conf[:image_size_y] + 5 # with left space
21
+ end
22
+
23
+ @label = Qt::Label.new('', self)
24
+
25
+ show
26
+ update
27
+ end
28
+
29
+ def word
30
+ word = Lingvo::Models::English.rand(1).first
31
+ Console.no_word if word.nil?
32
+ label = "<div style='font-size: #{@conf[:eng_size]}px; color: #{@conf[:eng_fg]}'>#{word.eng}</div>"
33
+ label += "<div style='font-size: #{@conf[:transcr_size]}px; color: #{@conf[:transcr_fg]};'>#{word.transcr}</div>" if @conf[:transcr] == 'on'
34
+ label += "<div style='font-size: #{@conf[:ru_size]}px; color: #{@conf[:ru_fg]}'>#{word.ru}</div>"
35
+ end
36
+
37
+ def update_word
38
+ @label.setText(word)
39
+ @label.setGeometry(@conf[:size_for_image], 0, @label.sizeHint.width, @label.sizeHint.height)
40
+ setFixedSize(@label.sizeHint.width + @conf[:size_for_image], @label.sizeHint.height)
41
+ end
42
+
43
+ def update_position
44
+ screen_w = Qt::Application::desktop.width.to_i
45
+ screen_w -= 10 # left space
46
+ screen_w -= @label.sizeHint.width # base label
47
+ screen_w -= @conf[:size_for_image]# image space
48
+
49
+ move(screen_w, 20)
50
+ end
51
+
52
+ def update
53
+ update_word
54
+ update_position
55
+ end
56
+
57
+ def close
58
+ Simple.app.quit
59
+ end
60
+ end
61
+
62
+ class Simple
63
+ class << self
64
+ attr_accessor :app
65
+
66
+ def run
67
+ @app = Qt::Application.new ARGV
68
+ Widget.new
69
+ @app.exec
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,11 @@
1
+ module Lingvo
2
+ module Models
3
+ class English < ActiveRecord::Base
4
+ self.table_name = 'english'
5
+
6
+ validates :eng, :ru, presence: true, uniqueness: true
7
+
8
+ scope :rand, -> (count) { order("RANDOM()").limit(count) }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ require 'nokogiri'
2
+
3
+ module Lingvo
4
+ module Parsers
5
+ class Lingualeo
6
+ attr_reader :words
7
+
8
+ def initialize(path)
9
+ @words = []
10
+ resource = Nokogiri::HTML(File.open(path))
11
+ resource.xpath('//body/table/tbody/tr').each do |tr|
12
+ tds = tr.css('td')
13
+
14
+ next if tds[0].nil?
15
+ @words << {
16
+ eng: tds[1].content.strip,
17
+ transcr: tds[2].content.strip,
18
+ ru: tds[3].content.strip,
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Lingvo
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lingvo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lingvo"
8
+ spec.version = Lingvo::VERSION
9
+ spec.authors = ["Igor G"]
10
+ spec.email = ["igor.s04@mail.ru"]
11
+ spec.description = %q{Will help don't forget english words}
12
+ spec.summary = %q{Lingvo - easy helper in learning english words}
13
+ spec.homepage = 'https://github.com/igor04/lingvo'
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "qtbindings"
25
+
26
+ spec.add_development_dependency "activerecord"
27
+ spec.add_development_dependency "sqlite3"
28
+ spec.add_development_dependency "activerecord-jdbcsqlite3-adapter"
29
+ spec.add_development_dependency "nokogiri"
30
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lingvo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Igor G
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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: rspec
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: qtbindings
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: activerecord
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: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activerecord-jdbcsqlite3-adapter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: nokogiri
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Will help don't forget english words
126
+ email:
127
+ - igor.s04@mail.ru
128
+ executables:
129
+ - lingvo
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - bin/lingvo
139
+ - lib/lingvo.rb
140
+ - lib/lingvo/config/config.rb
141
+ - lib/lingvo/config/default.yaml
142
+ - lib/lingvo/console/command.rb
143
+ - lib/lingvo/db/connection.rb
144
+ - lib/lingvo/db/migration/20120222153619_english.rb
145
+ - lib/lingvo/gui/img/eng.png
146
+ - lib/lingvo/gui/notify.rb
147
+ - lib/lingvo/gui/widget.rb
148
+ - lib/lingvo/models/english.rb
149
+ - lib/lingvo/parsers/lingualeo_parser.rb
150
+ - lib/lingvo/version.rb
151
+ - lingvo.gemspec
152
+ homepage: https://github.com/igor04/lingvo
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.0.3
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Lingvo - easy helper in learning english words
176
+ test_files: []