lingvo 0.0.3 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 151c38291271ca86091ba8427695aedbb5dc9d71
4
- data.tar.gz: a1761229c5b0aa0d66dd6cc99ff075d55ea2fcd8
3
+ metadata.gz: 15e28bdde10ad7b90d0f0b1305ac90ea8ed55884
4
+ data.tar.gz: 720354fa2d7383439f58ee5895b964f3f8507bb8
5
5
  SHA512:
6
- metadata.gz: 00eb0bc2db5822cf2776b44d087aa7e72aaaedd5c5439d04cd06959a0e85d00397c339ad1cd059cf21f169a2c7d522ad210c5b42038ebbeb18a5d91bb0eecd51
7
- data.tar.gz: 8e237c6192e08142dffcbabf5687a22dad6ea1bfc0280e2fcd94b92f59ab64a81ba00a16e80b5f42985fca50d79ac2d16f9257d41d6fa77ca65a67e9898cb2cf
6
+ metadata.gz: de5dc24fce0c5059c0977bb191ef48926a2f56b325faf43eb95bc0effed959aa612abbb88aab65dfefeeb434867b1f7b7a8bd544c393ce438d857395edf29be4
7
+ data.tar.gz: 23704a26eada3b3925950eb8361c5fa82ce285f07bf891e504897e7fe4a2a4408986aa05436d3d33c4caba79dd4a5f4da3f9a81babbdf09156a88dae6be6b2b6
data/README.md CHANGED
@@ -7,24 +7,34 @@
7
7
  $ gem install lingvo
8
8
 
9
9
  ## Usage
10
+ First you need parse some LinguaLeo word print page.
10
11
 
11
12
  Options:
13
+ > `--parse file` - parse lingvoleo HTML file with words
12
14
 
13
- > --parse file - parse lingovleo HTML file with words
15
+ > `--rand count` - show 'n' random records
14
16
 
15
- > --rand count - show 'n' random records
17
+ > `--notify` - show `word - translation` with your notification
16
18
 
17
- > --nitify - send show word - translation with your notification
19
+ > `--gui` - show words in simpe window
18
20
 
19
- > --gui - show words in simpe window
21
+ > key: n - show next word
20
22
 
21
- > key: n - show next word
23
+ > q - close window
22
24
 
23
- > q - close window
25
+ > `--wc f1 [f2]` - parse text file(f1), and write statistic to file(f2) or show if file(f2) isn't specify
24
26
 
25
- > --size - show words count
27
+ > `--size` - show words count
26
28
 
27
- > -h - show this help
29
+ > `-v` - show version
30
+
31
+ > `-h` - show this help
32
+
33
+ Setup as cronjob:
34
+
35
+ `*/5 * * * * lingvo --notify`
36
+
37
+ `*/7 * * * * env DISPLAY=:0 lingvo --gui`
28
38
 
29
39
  ## Contributing
30
40
 
data/bin/lingvo CHANGED
@@ -7,10 +7,12 @@ module Lingvo
7
7
  case ARGV[0]
8
8
  when '--parse' then Command.parse ARGV[1]
9
9
  when '--rand' then Command.rand ARGV[1]
10
+ when '--wc' then Command.words_counter ARGV[1], ARGV[2]
10
11
  when '--size' then Command.size
11
12
  when '--notify'then Command.notify
12
13
  when '--gui'then Command.gui
13
14
  when '-h' then Command.help
15
+ when '-v' then puts VERSION
14
16
 
15
17
  else
16
18
  Command.help
@@ -4,6 +4,7 @@ require 'lingvo/config/config'
4
4
 
5
5
  require 'lingvo/console/command'
6
6
  require 'lingvo/parsers/lingualeo_parser'
7
+ require 'lingvo/parsers/words_counter_parser'
7
8
 
8
9
  require 'lingvo/db/connection'
9
10
  require 'lingvo/models/english'
@@ -1,6 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'yaml'
3
3
 
4
+
4
5
  module Lingvo
5
6
  module Config
6
7
  class << self
@@ -16,6 +17,8 @@ module Lingvo
16
17
  DB_FILE = File.join BASE_DIR, 'english_words.sqlite3'
17
18
  CUSTOM_CONFIG = File.join BASE_DIR, 'config.yaml'
18
19
 
20
+ $stderr = File.open File.join(BASE_DIR + 'app.log'), 'w'
21
+
19
22
  unless File.exists? BASE_DIR
20
23
  FileUtils.mkdir BASE_DIR, mode: 0755
21
24
  end
File without changes
@@ -4,14 +4,17 @@ module Lingvo
4
4
  Lingvo #{VERSION}
5
5
 
6
6
  Options:
7
- --parse file - parse lingovleo HTML file with words
7
+ --parse file - parse lingvoleo HTML file with words
8
8
  --rand count - show 'n' random records
9
- --nitify - send show word - translation with your notification
9
+ --notify - show `word - translation` with your notification
10
10
  --gui - show words in simpe window
11
11
  key: n - show next word
12
12
  q - close window
13
13
 
14
+ --wc f1 [f2] - parse text file(f1), and write statistic to file(f2) or show if file(f2) isn't specify
15
+
14
16
  --size - show words count
17
+ -v - show version
15
18
  -h - show this help
16
19
 
17
20
  """
@@ -37,27 +40,25 @@ Options:
37
40
  class Command
38
41
  class << self
39
42
  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
43
+ return file_not_found unless File.exists? path
44
+ Parsers::Lingualeo.new(path) { |word| Models::English.create word }
45
+ size
46
+ end
47
+
48
+ def words_counter(from, to)
49
+ return file_not_found if !File.exists?(from) || (to && !File.exist?(to))
50
+ Parsers::WordsCounter.new from, to
48
51
  end
49
52
 
50
53
  def rand(count)
51
54
  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}"
55
+ Models::English.rand(count).each do |word|
56
+ printf "%-20s %-20s %s\n", word.eng, word.transcr, word.ru
56
57
  end
57
58
  end
58
59
 
59
60
  def size
60
- puts "You have #{Models::English.count} words"
61
+ puts "\nYou have #{Models::English.count} words\n"
61
62
  end
62
63
 
63
64
  def notify
@@ -71,6 +72,12 @@ Options:
71
72
  def help
72
73
  puts HELP
73
74
  end
75
+
76
+ private
77
+
78
+ def file_not_found
79
+ puts "\nFile not found!\n"
80
+ end
74
81
  end
75
82
  end
76
83
  end
@@ -8,6 +8,7 @@ module Lingvo
8
8
  database: Config::DB_FILE
9
9
  )
10
10
 
11
+ ActiveRecord::Migration.verbose = false
11
12
  ActiveRecord::Migrator.migrate "#{Config::LINGVO_DIR}/db/migration/"
12
13
  end
13
14
  end
File without changes
File without changes
File without changes
@@ -6,6 +6,8 @@ module Lingvo
6
6
  validates :eng, :ru, presence: true, uniqueness: true
7
7
 
8
8
  scope :rand, -> (count) { order("RANDOM()").limit(count) }
9
+
10
+ after_save -> { print "·" }
9
11
  end
10
12
  end
11
13
  end
@@ -3,20 +3,20 @@ require 'nokogiri'
3
3
  module Lingvo
4
4
  module Parsers
5
5
  class Lingualeo
6
- attr_reader :words
7
-
8
- def initialize(path)
9
- @words = []
10
- resource = Nokogiri::HTML(File.open(path))
6
+ def initialize(path, &block)
7
+ resource = Nokogiri::HTML File.open(path)
11
8
  resource.xpath('//body/table/tbody/tr').each do |tr|
12
9
  tds = tr.css('td')
13
10
 
14
11
  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
- }
12
+
13
+ eng = tds[1].content.strip
14
+ transcr = tds[2].content.strip
15
+ ru = tds[3].content.strip
16
+
17
+ if eng.size < 20 && transcr.size < 20 && ru.size < 20
18
+ block.call eng: eng, transcr: transcr, ru: ru
19
+ end
20
20
  end
21
21
  end
22
22
  end
@@ -0,0 +1,36 @@
1
+ module Lingvo
2
+ module Parsers
3
+ class WordsCounter
4
+ def initialize(from, to=nil)
5
+ @words = read from
6
+
7
+ if to
8
+ write to
9
+ else
10
+ show
11
+ end
12
+ end
13
+
14
+ def count
15
+ counter = {}
16
+ @words.each { |word| counter[word] = counter[word].to_i + 1 }
17
+ counter.sort_by { |word, count| count }.reverse
18
+ end
19
+
20
+ def show
21
+ count.each { |data| puts "#{data[1]} : #{data[0]}" }
22
+ end
23
+
24
+ def read from
25
+ file = File.open(from).read
26
+ file.downcase.scan(/([a-z']+)/).flatten
27
+ end
28
+
29
+ def write(to)
30
+ File.open to, 'w' do |file|
31
+ count.each { |data| file.write "#{data[1]} : #{data[0]}\n" }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module Lingvo
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,125 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lingvo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor G
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-17 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: qtbindings
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activerecord
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sqlite3
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: activerecord-jdbcsqlite3-adapter
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: nokogiri
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  description: Will help don't forget english words
@@ -130,7 +130,7 @@ executables:
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
- - .gitignore
133
+ - ".gitignore"
134
134
  - Gemfile
135
135
  - LICENSE.txt
136
136
  - README.md
@@ -147,6 +147,7 @@ files:
147
147
  - lib/lingvo/gui/widget.rb
148
148
  - lib/lingvo/models/english.rb
149
149
  - lib/lingvo/parsers/lingualeo_parser.rb
150
+ - lib/lingvo/parsers/words_counter_parser.rb
150
151
  - lib/lingvo/version.rb
151
152
  - lingvo.gemspec
152
153
  homepage: https://github.com/igor04/lingvo
@@ -159,17 +160,17 @@ require_paths:
159
160
  - lib
160
161
  required_ruby_version: !ruby/object:Gem::Requirement
161
162
  requirements:
162
- - - '>='
163
+ - - ">="
163
164
  - !ruby/object:Gem::Version
164
165
  version: '0'
165
166
  required_rubygems_version: !ruby/object:Gem::Requirement
166
167
  requirements:
167
- - - '>='
168
+ - - ">="
168
169
  - !ruby/object:Gem::Version
169
170
  version: '0'
170
171
  requirements: []
171
172
  rubyforge_project:
172
- rubygems_version: 2.0.3
173
+ rubygems_version: 2.2.2
173
174
  signing_key:
174
175
  specification_version: 4
175
176
  summary: Lingvo - easy helper in learning english words