the-free-dictionary 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 +7 -0
- data/.github/workflows/ci.yml +30 -0
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/.rubocop.yml +45 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +83 -0
- data/LICENSE +21 -0
- data/README.md +56 -0
- data/lib/the_free_dictionary/chinese.rb +10 -0
- data/lib/the_free_dictionary/dictionary.rb +53 -0
- data/lib/the_free_dictionary/english.rb +10 -0
- data/lib/the_free_dictionary/french.rb +10 -0
- data/lib/the_free_dictionary/german.rb +10 -0
- data/lib/the_free_dictionary/italian.rb +10 -0
- data/lib/the_free_dictionary/russian.rb +10 -0
- data/lib/the_free_dictionary/spanish.rb +10 -0
- data/lib/the_free_dictionary.rb +10 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d9aff2d40d40a07e97b0696262cf690fa7c4bf1ea79e629f6f270b4d36d7a37a
|
4
|
+
data.tar.gz: caec3b23b39913fa49bb664897376bc727312401f13c446862e6b2f79accd0e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cec7265c3859bfa80612f1a23e0fb9a6603bc55f11d77a61b70c0cc12aff96c14e067816ad445daacc7de7abcf1e72fad86a41a92446254fa1a98b0cb0536f42
|
7
|
+
data.tar.gz: 469167d55b50a3cb7d9a4667222e3335a75834575a6e118cf314d286a4851b12bdc9f4bade539f122f8787e41ee033990403cd8fb06970ddd8341d58a65643f5
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "main" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "main" ]
|
8
|
+
|
9
|
+
permissions:
|
10
|
+
contents: read
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
test:
|
14
|
+
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
strategy:
|
17
|
+
matrix:
|
18
|
+
ruby-version: [ '3.3.0' ]
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v3
|
22
|
+
- name: Set up Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby-version }}
|
26
|
+
bundler-cache: true
|
27
|
+
- name: Check Rubocop compliance
|
28
|
+
run: bundle exec rubocop --format github
|
29
|
+
- name: Run tests
|
30
|
+
run: bundle exec rspec
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.env
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
require:
|
3
|
+
- rubocop-rake
|
4
|
+
- rubocop-rspec
|
5
|
+
- rubocop-performance
|
6
|
+
|
7
|
+
AllCops:
|
8
|
+
NewCops: enable
|
9
|
+
TargetRubyVersion: 3.3
|
10
|
+
|
11
|
+
Style/Documentation:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Metrics/BlockLength:
|
15
|
+
AllowedMethods:
|
16
|
+
- context
|
17
|
+
- describe
|
18
|
+
- task
|
19
|
+
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Exclude:
|
22
|
+
- spec/**/*
|
23
|
+
|
24
|
+
Layout/LineLength:
|
25
|
+
Max: 120
|
26
|
+
|
27
|
+
Lint/MissingSuper:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
RSpec/MultipleMemoizedHelpers:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
RSpec/NestedGroups:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
RSpec/ExampleLength:
|
37
|
+
Exclude:
|
38
|
+
- 'spec/**/*'
|
39
|
+
|
40
|
+
RSpec/MultipleExpectations:
|
41
|
+
Exclude:
|
42
|
+
- 'spec/**/*'
|
43
|
+
|
44
|
+
Gemspec/RequiredRubyVersion:
|
45
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.8.7)
|
5
|
+
public_suffix (>= 2.0.2, < 7.0)
|
6
|
+
ast (2.4.2)
|
7
|
+
bigdecimal (3.1.8)
|
8
|
+
crack (1.0.0)
|
9
|
+
bigdecimal
|
10
|
+
rexml
|
11
|
+
diff-lcs (1.5.1)
|
12
|
+
hashdiff (1.1.0)
|
13
|
+
json (2.7.2)
|
14
|
+
language_server-protocol (3.17.0.3)
|
15
|
+
parallel (1.25.1)
|
16
|
+
parser (3.3.3.0)
|
17
|
+
ast (~> 2.4.1)
|
18
|
+
racc
|
19
|
+
public_suffix (6.0.0)
|
20
|
+
racc (1.8.0)
|
21
|
+
rainbow (3.1.1)
|
22
|
+
rake (13.2.1)
|
23
|
+
regexp_parser (2.9.2)
|
24
|
+
rexml (3.3.1)
|
25
|
+
strscan
|
26
|
+
rspec (3.13.0)
|
27
|
+
rspec-core (~> 3.13.0)
|
28
|
+
rspec-expectations (~> 3.13.0)
|
29
|
+
rspec-mocks (~> 3.13.0)
|
30
|
+
rspec-core (3.13.0)
|
31
|
+
rspec-support (~> 3.13.0)
|
32
|
+
rspec-expectations (3.13.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.13.0)
|
35
|
+
rspec-mocks (3.13.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.13.0)
|
38
|
+
rspec-support (3.13.1)
|
39
|
+
rubocop (1.64.1)
|
40
|
+
json (~> 2.3)
|
41
|
+
language_server-protocol (>= 3.17.0)
|
42
|
+
parallel (~> 1.10)
|
43
|
+
parser (>= 3.3.0.2)
|
44
|
+
rainbow (>= 2.2.2, < 4.0)
|
45
|
+
regexp_parser (>= 1.8, < 3.0)
|
46
|
+
rexml (>= 3.2.5, < 4.0)
|
47
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
48
|
+
ruby-progressbar (~> 1.7)
|
49
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
50
|
+
rubocop-ast (1.31.3)
|
51
|
+
parser (>= 3.3.1.0)
|
52
|
+
rubocop-performance (1.21.1)
|
53
|
+
rubocop (>= 1.48.1, < 2.0)
|
54
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
55
|
+
rubocop-rake (0.6.0)
|
56
|
+
rubocop (~> 1.0)
|
57
|
+
rubocop-rspec (3.0.2)
|
58
|
+
rubocop (~> 1.61)
|
59
|
+
ruby-progressbar (1.13.0)
|
60
|
+
strscan (3.1.0)
|
61
|
+
unicode-display_width (2.5.0)
|
62
|
+
vcr (6.2.0)
|
63
|
+
webmock (3.23.1)
|
64
|
+
addressable (>= 2.8.0)
|
65
|
+
crack (>= 0.3.2)
|
66
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
x86_64-linux
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
rake
|
74
|
+
rspec
|
75
|
+
rubocop
|
76
|
+
rubocop-performance
|
77
|
+
rubocop-rake
|
78
|
+
rubocop-rspec
|
79
|
+
vcr
|
80
|
+
webmock
|
81
|
+
|
82
|
+
BUNDLED WITH
|
83
|
+
2.5.13
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Anatoly Busygin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# TheFreeDictionary
|
2
|
+
|
3
|
+
TheFreeDictionary is a versatile Ruby library that fetches information about words from various languages. It retrieves the pronunciation link (audio) and the transcription for a given word from [The Free Dictionary website](https://www.thefreedictionary.com).
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- Fetches audio pronunciation links
|
8
|
+
- Retrieves phonetic transcription of words
|
9
|
+
- Supports multiple languages including English, French, German, Italian, Russian, Spanish, and Chinese
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'the-free-dictionary'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
```shell
|
22
|
+
$ bundle install
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
```shell
|
28
|
+
$ gem install the-free-dictionary
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Here's a quick example to get you started:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'the-free-dictionary'
|
37
|
+
|
38
|
+
dictionary = TheFreeDictionary::English.new
|
39
|
+
result = dictionary.find('glossary')
|
40
|
+
|
41
|
+
puts "Sound URL: #{result[:sound]}"
|
42
|
+
puts "Transcription: #{result[:transcription]}"
|
43
|
+
```
|
44
|
+
|
45
|
+
## Supported Languages
|
46
|
+
|
47
|
+
TheFreeDictionary provides classes for different languages:
|
48
|
+
- `TheFreeDictionary::English`
|
49
|
+
- `TheFreeDictionary::Spanish`
|
50
|
+
- `TheFreeDictionary::French`
|
51
|
+
- `TheFreeDictionary::German`
|
52
|
+
- `TheFreeDictionary::Italian`
|
53
|
+
- `TheFreeDictionary::Russian`
|
54
|
+
- `TheFreeDictionary::Chinese`
|
55
|
+
|
56
|
+
Each class has a `find` method that takes a word as an argument and returns a hash with `:sound` and `:transcription`.
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module TheFreeDictionary
|
6
|
+
class Dictionary
|
7
|
+
attr_accessor :language, :region
|
8
|
+
|
9
|
+
def find(statement)
|
10
|
+
uri = build_uri(statement)
|
11
|
+
response = fetch(uri)
|
12
|
+
sound = build_sound_url(response)
|
13
|
+
transcription = fetch_transcription(response)
|
14
|
+
|
15
|
+
{ sound:, transcription: }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def fetch(uri)
|
21
|
+
Net::HTTP.get_response(uri)
|
22
|
+
rescue Socket::ResolutionError
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_uri(statement)
|
27
|
+
URI(URI::DEFAULT_PARSER.escape("https://#{@language}.thefreedictionary.com/#{statement}"))
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_sound_url(response)
|
31
|
+
sound_data = response.body.match(%r{#{@language}/#{@region}[^"]+})
|
32
|
+
if sound_data.nil?
|
33
|
+
''
|
34
|
+
else
|
35
|
+
"https://img2.tfd.com/pron/mp3/#{sound_data[0]}.mp3"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch_transcription(response)
|
40
|
+
regex = %r{<span[^>]*onclick="pron_key\(1\)"[^>]*class="pron"[^>]*>\s*\(?([^)]+)\)?\s*</span>}
|
41
|
+
transcription_data = response.body.match(regex)
|
42
|
+
if transcription_data.nil?
|
43
|
+
''
|
44
|
+
else
|
45
|
+
decode_html_entities(transcription_data[1].force_encoding('UTF-8'))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def decode_html_entities(string)
|
50
|
+
string.gsub(/&#(\d+);/) { |_match| ::Regexp.last_match(1).to_i.chr(Encoding::UTF_8) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'the_free_dictionary/dictionary'
|
4
|
+
require_relative 'the_free_dictionary/english'
|
5
|
+
require_relative 'the_free_dictionary/spanish'
|
6
|
+
require_relative 'the_free_dictionary/french'
|
7
|
+
require_relative 'the_free_dictionary/german'
|
8
|
+
require_relative 'the_free_dictionary/italian'
|
9
|
+
require_relative 'the_free_dictionary/chinese'
|
10
|
+
require_relative 'the_free_dictionary/russian'
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: the-free-dictionary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anatoly Busygin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: anatolyb94@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".github/workflows/ci.yml"
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- lib/the_free_dictionary.rb
|
28
|
+
- lib/the_free_dictionary/chinese.rb
|
29
|
+
- lib/the_free_dictionary/dictionary.rb
|
30
|
+
- lib/the_free_dictionary/english.rb
|
31
|
+
- lib/the_free_dictionary/french.rb
|
32
|
+
- lib/the_free_dictionary/german.rb
|
33
|
+
- lib/the_free_dictionary/italian.rb
|
34
|
+
- lib/the_free_dictionary/russian.rb
|
35
|
+
- lib/the_free_dictionary/spanish.rb
|
36
|
+
homepage: https://github.com/Suban05/the-free-dictionary
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata:
|
40
|
+
rubygems_mfa_required: 'true'
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.5.10
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: TheFreeDictionary is a gem that fetches information about words from https://www.thefreedictionary.com/
|
60
|
+
test_files: []
|