vocabulary_to_csv 0.1.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
+ SHA256:
3
+ metadata.gz: cba4ccea2221a89e008d868a03d59a1132bd6d0f01997402b49205f85cfb75eb
4
+ data.tar.gz: 97ef85268c0cffa317a99ad3d828ba652f8e66574bed23e1f572a9e7148c1d3b
5
+ SHA512:
6
+ metadata.gz: 133e764a16bd24995b646851b4e5c652704606932dd960bfff5d45db94ffece1564788566807c57bc74f74928757938bd589009f0036cf47a7d613a6e1ad149d
7
+ data.tar.gz: 7664d1c2bd4ea8a129306a863100fc45abf16558063acb0f46b1d125e1a28e231677eb17de21afd061a27044d6d59cc897eb1f5f0fed0aeb8469530a458f9214
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-12-11
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Jakub Polak
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # vocabulary_to_csv
2
+
3
+ `vocabulary_to_csv` is a Ruby gem designed for extracting vocabulary lists from Vocabulary.com and saving the data into a CSV file. It employs the Nokogiri gem for web scraping.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add vocabulary_to_csv
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install vocabulary_to_csv
14
+
15
+ ## Usage
16
+
17
+ ````ruby
18
+ require 'vocabulary_to_csv'
19
+
20
+ # Create an instance of VocabularyToCSV
21
+ # Pass the vocabulary list ID
22
+ parser = VocabularyToCsv.new('271244')
23
+
24
+ # Parse and save data to CSV (Examples column included by default)
25
+ parser.parse_and_save_to_csv(examples: true)
26
+ ````
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kupolak/vocabulary_to_csv. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/kupolak/vocabulary_to_csv/blob/main/CODE_OF_CONDUCT.md).
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
35
+
36
+ Make sure to comply with Vocabulary.com's terms of service when using this gem for web scraping.
37
+ The gem assumes you are providing a valid vocabulary list ID as an argument. The use of a complete URL is not officially supported and may lead to unexpected behavior.
38
+ The gem may not work correctly if Vocabulary.com's website structure changes.
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the VocabularyToCsv project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kupolak/vocabulary_to_csv/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class VocabularyToCsv
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "vocabulary_to_csv/version"
4
+
5
+ require "nokogiri"
6
+ require "open-uri"
7
+ require "csv"
8
+
9
+ # Interface to interact with vocabulary.com
10
+ class VocabularyToCsv
11
+ def initialize(id)
12
+ @id = id
13
+ @url = "https://www.vocabulary.com/lists/#{id}"
14
+ end
15
+
16
+ def parse_and_save_to_csv(examples: true)
17
+ words = scrape_words
18
+ definitions = scrape_definitions
19
+ examples_data = examples ? scrape_examples : Array.new(words.size, "")
20
+
21
+ write_to_csv(words, definitions, examples_data)
22
+ end
23
+
24
+ private
25
+
26
+ def scrape_words
27
+ page.css("a.word").map { |word| word.text.strip }
28
+ end
29
+
30
+ def scrape_definitions
31
+ page.css("div.definition").map { |definition| definition.text.strip }
32
+ end
33
+
34
+ def scrape_examples
35
+ page.css("div.example").map { |example| example.text.strip.gsub(/[^[:print:]]/, "").gsub("â", "") }
36
+ end
37
+
38
+ def write_to_csv(words, definitions, examples, include_examples_header: true)
39
+ words_definitions_examples = words.zip(definitions, examples)
40
+
41
+ CSV.open("#{@id}.csv", "w") do |csv|
42
+ csv << (%w[Word Definition] + (include_examples_header ? ["Example"] : []))
43
+
44
+ words_definitions_examples.each do |word, definition, example|
45
+ csv << ([word, definition] + (include_examples_header ? [example] : []))
46
+ end
47
+ end
48
+ end
49
+
50
+ def page
51
+ @page ||= Nokogiri::HTML(URI.parse(@url).open)
52
+ end
53
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/vocabulary_to_csv/version"
4
+
5
+ # rubocop:disable Layout/LineLength
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vocabulary_to_csv"
8
+ spec.version = VocabularyToCsv::VERSION
9
+ spec.authors = ["Jakub Polak"]
10
+ spec.email = ["jakub.polak.vz@gmail.com"]
11
+
12
+ spec.summary = "vocabulary_to_csv is a Ruby gem designed for extracting vocabulary lists from vocabulary.com and saving the data into a CSV file."
13
+ spec.description = "vocabulary_to_csv is a Ruby gem designed for extracting vocabulary lists from Vocabulary.com and saving the data into a CSV file. It employs the Nokogiri gem for web scraping."
14
+ spec.homepage = "https://github.com/kupolak/vocabulary_to_csv"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 3.2.0"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/kupolak/vocabulary_to_csv"
20
+ spec.metadata["changelog_uri"] = "https://github.com/kupolak/vocabulary_to_csv/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (File.expand_path(f) == __FILE__) ||
27
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile Gemfile.lock .gitignore .rubocop])
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ spec.add_dependency "csv", "~> 3.2"
36
+ spec.add_dependency "nokogiri", "~> 1.15"
37
+ spec.metadata["rubygems_mfa_required"] = "true"
38
+ end
39
+ # rubocop:enable Layout/LineLength
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vocabulary_to_csv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jakub Polak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: csv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ description: vocabulary_to_csv is a Ruby gem designed for extracting vocabulary lists
42
+ from Vocabulary.com and saving the data into a CSV file. It employs the Nokogiri
43
+ gem for web scraping.
44
+ email:
45
+ - jakub.polak.vz@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - CHANGELOG.md
51
+ - CODE_OF_CONDUCT.md
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/vocabulary_to_csv.rb
56
+ - lib/vocabulary_to_csv/version.rb
57
+ - vocabulary_to_csv.gemspec
58
+ homepage: https://github.com/kupolak/vocabulary_to_csv
59
+ licenses:
60
+ - MIT
61
+ metadata:
62
+ homepage_uri: https://github.com/kupolak/vocabulary_to_csv
63
+ source_code_uri: https://github.com/kupolak/vocabulary_to_csv
64
+ changelog_uri: https://github.com/kupolak/vocabulary_to_csv/CHANGELOG.md
65
+ rubygems_mfa_required: 'true'
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.2.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.4.16
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: vocabulary_to_csv is a Ruby gem designed for extracting vocabulary lists
85
+ from vocabulary.com and saving the data into a CSV file.
86
+ test_files: []