sjp 1.0.0

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: ce6502069ede1f4e4b57dd005143764b317d5c36
4
+ data.tar.gz: f5e85980e06657874e5c3ae061a934fd4d9e9dfa
5
+ SHA512:
6
+ metadata.gz: 91f2d475d2a6817720a04fe872ee5c71c02134b831363f94d8a6c407837822d0f8eb44ee2a5724da2ba602de9e6fee8fde3cb9339681b59ea5c3022c85b65e6c
7
+ data.tar.gz: 35dd48473403da72ad6d1d043b2d2eb4df2bcb26fbf91591d2083b68ee40a36fa5c4b11ceca6d1aee51fc3ffd018fb9695373366bc792e54dbd43ef24625b4ce
data/.gitignore ADDED
@@ -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/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
4
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ sjp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sjp.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :bundler do
5
+ watch('Gemfile')
6
+ watch(/^.+\.gemspec/)
7
+ end
8
+
9
+ guard :rspec do
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^lib/(.+)\.rb$}) do |array|
12
+ name = array.last
13
+ "spec/#{name}_spec.rb"
14
+ end
15
+ watch('spec/spec_helper.rb') { 'spec' }
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Michał Skóra
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Sjp
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sjp'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sjp
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/sjp/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/lib/sjp/parser.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'cgi'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+
5
+ # Slownik jezyka polskiego
6
+ module Sjp
7
+ # Parser class
8
+ class Parser
9
+ attr_reader :word, :page, :html
10
+
11
+ def initialize
12
+ @word, @html, @page, @hash = '', '', nil, {}
13
+ end
14
+
15
+ def word=(text)
16
+ @word = text
17
+ @encoded_word = CGI.escape text
18
+ self.html = open(path).read
19
+ table
20
+ end
21
+
22
+ def exist?
23
+ ![
24
+ 'słowo występuje tylko jako część innych haseł',
25
+ 'nie występuje w słowniku'
26
+ ].include? status
27
+ end
28
+
29
+ def allowed?
30
+ # TODO: tests for exist and allow
31
+ # exist? && (status != 'niedopuszczalne w grach')
32
+ status == 'dopuszczalne w grach ✔'
33
+ end
34
+
35
+ def variety?
36
+ @hash['odmienność:'] == 'tak'
37
+ end
38
+
39
+ def description
40
+ @page.css('p')[3].text
41
+ end
42
+
43
+ def html=(value)
44
+ @html = value
45
+ @page = Nokogiri::HTML(@html)
46
+ end
47
+
48
+ private
49
+
50
+ def host
51
+ 'http://sjp.pl/'
52
+ end
53
+
54
+ def path
55
+ "#{host}#{@encoded_word}"
56
+ end
57
+
58
+ def status
59
+ @page.search('p').first.text
60
+ end
61
+
62
+ def table
63
+ @page.search('table tr').each do |row|
64
+ key, value = row.search('th').text, row.search('td').text
65
+ @hash[key] = value
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,4 @@
1
+ # Gem version
2
+ module Sjp
3
+ VERSION = '1.0.0'
4
+ end
data/lib/sjp.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'sjp/parser'
2
+ require 'sjp/version'
data/sjp.gemspec ADDED
@@ -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 'sjp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sjp'
8
+ spec.version = Sjp::VERSION
9
+ spec.authors = ['Michał Skóra', 'Aleksander Małaszkiewicz']
10
+ spec.email = ['info@fractalsoft.org']
11
+ spec.summary = 'Slownik Jezyka Polskiego'
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = %w(lib)
19
+
20
+ spec.add_dependency 'nokogiri', '~> 1.6'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.5'
23
+ spec.add_development_dependency 'rake', '~> 0'
24
+ spec.add_development_dependency 'rspec', '~> 3.3'
25
+ spec.add_development_dependency 'guard', '~> 0'
26
+ spec.add_development_dependency 'guard-bundler', '~> 0'
27
+ spec.add_development_dependency 'guard-rspec', '~> 0'
28
+ # spec.add_development_dependency 'mutant-rspec'
29
+ spec.add_development_dependency 'webmock', '~> 1.21'
30
+ end
@@ -0,0 +1,223 @@
1
+ require 'spec_helper'
2
+
3
+ # WebMock.enable!
4
+ # WebMock.disable!
5
+
6
+ describe Sjp::Parser do
7
+ let(:head) do
8
+ %(
9
+ <head>
10
+ <meta charset='utf-8'>
11
+ </head>
12
+ )
13
+ end
14
+ let(:row) {}
15
+ let(:table) { head + "<body><table>#{row}</table></body>" }
16
+
17
+ context '#word=' do
18
+ let(:text) { rand_text }
19
+ let(:body) { text }
20
+
21
+ # before { WebMock.enable! }
22
+ # before { WebMock.disable! }
23
+
24
+ it do
25
+ stub_request(:get, "sjp.pl/#{text}").to_return(
26
+ status: 200,
27
+ body: body,
28
+ headers: {}
29
+ )
30
+ subject.word = text
31
+ expect(subject.word).to eq(text)
32
+ end
33
+ end
34
+
35
+ # after { WebMock.disable! }
36
+ # before { WebMock.disable! }
37
+
38
+ context '#exist?' do
39
+ it do
40
+ stub_request(:get, 'sjp.pl/lorem').to_return(
41
+ status: 200,
42
+ body: head + '<body>
43
+ <p>nie występuje w słowniku</p>
44
+ </body>',
45
+ headers: {}
46
+ )
47
+ subject.word = 'lorem'
48
+ expect(subject).not_to be_exist
49
+ end
50
+
51
+ it do
52
+ stub_request(:get, 'sjp.pl/mama').to_return(
53
+ status: 200,
54
+ body: head + '<body><p></p></body>',
55
+ headers: {}
56
+ )
57
+ subject.word = 'mama'
58
+ expect(subject).to be_exist
59
+ end
60
+
61
+ it do
62
+ stub_request(:get, 'sjp.pl/stom').to_return(
63
+ status: 200,
64
+ body: head + '<body>
65
+ <p>słowo występuje tylko jako część innych haseł</p>
66
+ </body>',
67
+ headers: {}
68
+ )
69
+ subject.word = 'stom'
70
+ expect(subject).not_to be_exist
71
+ end
72
+ end
73
+
74
+ describe '#allowed?' do
75
+ let(:start) { head + '<body><p><b>' }
76
+ let(:stop) { '</b></p></body>' }
77
+ let(:body_allowed) { start + 'dopuszczalne w grach ✔' + stop }
78
+ let(:body_not_allowed) { start + 'niedopuszczalne w grach' + stop }
79
+
80
+ context 'true' do
81
+ it do
82
+ stub_request(:get, 'sjp.pl/mama').to_return(
83
+ status: 200,
84
+ body: body_allowed,
85
+ headers: {}
86
+ )
87
+ subject.word = 'mama'
88
+ expect(subject).to be_allowed
89
+ end
90
+
91
+ it do
92
+ stub_request(:get, 'sjp.pl/a+zatem').to_return(
93
+ status: 200,
94
+ body: body_allowed,
95
+ headers: {}
96
+ )
97
+ subject.word = 'a zatem'
98
+ expect(subject).to be_allowed
99
+ end
100
+
101
+ it do
102
+ stub_request(:get, 'sjp.pl/ta+ta+ta').to_return(
103
+ status: 200,
104
+ body: body_allowed,
105
+ headers: {}
106
+ )
107
+ subject.word = 'ta ta ta'
108
+ expect(subject).to be_allowed
109
+ end
110
+ end
111
+
112
+ context 'false' do
113
+ it do
114
+ stub_request(:get, 'sjp.pl/abc').to_return(
115
+ status: 200,
116
+ body: body_not_allowed,
117
+ headers: {}
118
+ )
119
+ subject.word = 'abc'
120
+ expect(subject).not_to be_allowed
121
+ end
122
+
123
+ it do
124
+ stub_request(:get, 'sjp.pl/mamma+mia').to_return(
125
+ status: 200,
126
+ body: body_not_allowed,
127
+ headers: {}
128
+ )
129
+ subject.word = 'mamma mia'
130
+ expect(subject).not_to be_allowed
131
+ end
132
+
133
+ it do
134
+ stub_request(:get, 'sjp.pl/a+maiore+ad+minus').to_return(
135
+ status: 200,
136
+ body: body_not_allowed,
137
+ headers: {}
138
+ )
139
+ subject.word = 'a maiore ad minus'
140
+ expect(subject).not_to be_allowed
141
+ end
142
+
143
+ # it '', :focus do
144
+ # subject.word = 'stom'
145
+ # expect(subject).not_to be_allowed
146
+ # end
147
+
148
+ # it do
149
+ # subject.word = 'a'
150
+ # expect(subject).not_to be_allowed
151
+ # end
152
+ end
153
+ end
154
+
155
+ describe '#variety?' do
156
+ context 'true' do
157
+ let(:row) { '<tr><th>odmienność:</th><td>tak</td></tr>' }
158
+ it do
159
+ stub_request(:get, 'sjp.pl/mama').to_return(
160
+ status: 200,
161
+ body: table,
162
+ headers: {}
163
+ )
164
+ subject.word = 'mama'
165
+ expect(subject).to be_variety
166
+ end
167
+ end
168
+
169
+ context 'false' do
170
+ let(:row) { '<tr><th>odmienność:</th><td>nie</td></tr>' }
171
+ it do
172
+ stub_request(:get, 'sjp.pl/mamma+mia').to_return(
173
+ status: 200,
174
+ body: table,
175
+ headers: {}
176
+ )
177
+ subject.word = 'mamma mia'
178
+ expect(subject).not_to be_variety
179
+ end
180
+ end
181
+ end
182
+
183
+ # after { WebMock.disable! }
184
+ # before { WebMock.disable! }
185
+
186
+ context '#description' do
187
+ let(:facebook) { '[czytaj: fejsbuk] amerykański serwis społecznościowy' }
188
+ let(:syn) { 'potomek płci męskiej' }
189
+ let(:corka) { 'dziecko płci żeńskiej' }
190
+
191
+ it do
192
+ stub_request(:get, 'sjp.pl/facebook').to_return(
193
+ status: 200,
194
+ body: head + "<body><p></p><p></p><p></p><p>#{facebook}</p></body>",
195
+ headers: {}
196
+ )
197
+ subject.word = 'facebook'
198
+ expect(subject.description).to eq(facebook)
199
+ # expect(subject.description).to eq('lorem ipsum')
200
+ end
201
+
202
+ it do
203
+ stub_request(:get, 'sjp.pl/syn').to_return(
204
+ status: 200,
205
+ body: head + "<body><p></p><p></p><p></p><p>#{syn}</p></body>",
206
+ headers: {}
207
+ )
208
+ subject.word = 'syn'
209
+ expect(subject.description).to eq(syn)
210
+ end
211
+
212
+ it do
213
+ # stub_request(:get, 'sjp.pl/c%F3rka').to_return(
214
+ stub_request(:get, 'sjp.pl/c%C3%B3rka').to_return(
215
+ status: 200,
216
+ body: head + "<body><p></p><p></p><p></p><p>#{corka}</p></body>",
217
+ headers: {}
218
+ )
219
+ subject.word = 'córka'
220
+ expect(subject.description).to eq(corka)
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,8 @@
1
+ require 'sjp'
2
+ require 'support/randomizer'
3
+ require 'webmock/rspec'
4
+
5
+ RSpec.configure do |config|
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+ end
@@ -0,0 +1,7 @@
1
+ def rand_text(size = 5)
2
+ ('a'..'z').to_a.sample(size).join
3
+ end
4
+
5
+ def rand_number(size, range)
6
+ (0..range).to_a.sample(size).join
7
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sjp
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michał Skóra
8
+ - Aleksander Małaszkiewicz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.6'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.6'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.5'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.5'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.3'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: guard
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: guard-bundler
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: guard-rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: webmock
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.21'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.21'
126
+ description:
127
+ email:
128
+ - info@fractalsoft.org
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".ruby-gemset"
136
+ - ".ruby-version"
137
+ - Gemfile
138
+ - Guardfile
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - lib/sjp.rb
143
+ - lib/sjp/parser.rb
144
+ - lib/sjp/version.rb
145
+ - sjp.gemspec
146
+ - spec/sjp/parser_spec.rb
147
+ - spec/spec_helper.rb
148
+ - spec/support/randomizer.rb
149
+ homepage: ''
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.6
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Slownik Jezyka Polskiego
173
+ test_files:
174
+ - spec/sjp/parser_spec.rb
175
+ - spec/spec_helper.rb
176
+ - spec/support/randomizer.rb