oxforddictionaries 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ed773a0967bb17aa08252f0c250fdc8a77f7dfb
4
+ data.tar.gz: c646ff4320765303482091977b1c562b86d7599a
5
+ SHA512:
6
+ metadata.gz: d543bb45088fba158e1bfb42bd0c9f057bac78b05aaa139a06de1887cbdcd86575303b69bb3842ce723610a3773cfddc34bc932453a9400d5d9e8a6c3e723262
7
+ data.tar.gz: 08c4196e332c23bec998312cc7f4da93c21e191b8b31a96e7fbf82fff692918a39c681d62491e048c77eee0fb3ec4baaf8842a1347c120534a2e44fca82b77d2
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ oxforddictionaries
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 oxforddictionaries.gemspec
4
+ gemspec
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
+ # Oxforddictionaries
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'oxforddictionaries'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install oxforddictionaries
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/oxforddictionaries/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 a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,7 @@
1
+ require 'oxforddictionaries/version'
2
+ require 'oxforddictionaries/parser'
3
+
4
+ # Oxforddictionaries module
5
+ module Oxforddictionaries
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,54 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ # Oxford Dictionaries module
5
+ module Oxforddictionaries
6
+ # Parser class
7
+ class Parser
8
+ attr_reader :word
9
+
10
+ def initialize
11
+ @word = ''
12
+ end
13
+
14
+ def exist?
15
+ (regex =~ single_match) || (regex =~ plural_matches)
16
+ end
17
+
18
+ def word=(text)
19
+ @word = text
20
+ @html = read
21
+ @page = Nokogiri::HTML(@html)
22
+ end
23
+
24
+ private
25
+
26
+ def host
27
+ 'http://www.oxforddictionaries.com/definition/english/'
28
+ end
29
+
30
+ def path
31
+ "#{host}#{word}"
32
+ end
33
+
34
+ def read
35
+ open(path).read
36
+ rescue
37
+ nil
38
+ end
39
+
40
+ def single_match
41
+ h1 = @page.search('h1').first
42
+ h1 && h1.text
43
+ end
44
+
45
+ def plural_matches
46
+ tag = @page.search("##{@word}").first
47
+ tag && tag.text
48
+ end
49
+
50
+ def regex
51
+ @regex ||= /.*[Dd]efinitions* of #{@word} in English:/
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module Oxforddictionaries
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'oxforddictionaries/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'oxforddictionaries'
8
+ spec.version = Oxforddictionaries::VERSION
9
+ spec.authors = ['Michał Skóra']
10
+ spec.email = %w(mskora@fractalsoft.org)
11
+ spec.summary = 'Oxford Dictionaries'
12
+ spec.description = 'Simple parser to english words'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency 'nokogiri', '~> 1.6'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake', '~> 0'
25
+ spec.add_development_dependency 'rspec', '~> 3.3'
26
+ spec.add_development_dependency 'webmock', '~> 1.21'
27
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Oxforddictionaries::Parser do
4
+ let(:word) { rand_text }
5
+
6
+ it 'initilizes with word as empty string' do
7
+ expect(subject.word).to eq ''
8
+ end
9
+
10
+ describe '#word=' do
11
+ it 'with empty string' do
12
+ subject.word = ''
13
+ expect(subject.word).to eq ''
14
+ end
15
+
16
+ it 'with something' do
17
+ subject.word = word
18
+ expect(subject.word).to eq word
19
+ end
20
+ end
21
+
22
+ describe '#exist?' do
23
+ context 'true' do
24
+ it 'if word is cat' do
25
+ subject.word = 'cat'
26
+ expect(subject).to be_exist
27
+ end
28
+
29
+ it 'if word is dog' do
30
+ subject.word = 'dog'
31
+ expect(subject).to be_exist
32
+ end
33
+
34
+ it 'if word is fish' do
35
+ subject.word = 'fish'
36
+ expect(subject).to be_exist
37
+ end
38
+ end
39
+
40
+ context 'false' do
41
+ it 'if word is lorem' do
42
+ subject.word = 'lorem'
43
+ expect(subject).not_to be_exist
44
+ end
45
+
46
+ it 'if word is ipsum' do
47
+ subject.word = 'ipsum'
48
+ expect(subject).not_to be_exist
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,8 @@
1
+ require 'oxforddictionaries'
2
+ require 'support/randomizer'
3
+
4
+ RSpec.configure do |config|
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ config.order = :random
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,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oxforddictionaries
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michał Skóra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.21'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.21'
83
+ description: Simple parser to english words
84
+ email:
85
+ - mskora@fractalsoft.org
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".ruby-gemset"
93
+ - ".ruby-version"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/oxforddictionaries.rb
99
+ - lib/oxforddictionaries/parser.rb
100
+ - lib/oxforddictionaries/version.rb
101
+ - oxforddictionaries.gemspec
102
+ - spec/oxforddictionaries/parser_spec.rb
103
+ - spec/spec_helper.rb
104
+ - spec/support/randomizer.rb
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Oxford Dictionaries
129
+ test_files:
130
+ - spec/oxforddictionaries/parser_spec.rb
131
+ - spec/spec_helper.rb
132
+ - spec/support/randomizer.rb