rwiki_links 0.1.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +11 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +12 -0
- data/lib/rwiki_links/build_cite_web_params.rb +49 -0
- data/lib/rwiki_links/combine_cite_web.rb +33 -0
- data/lib/rwiki_links/get_author.rb +59 -0
- data/lib/rwiki_links/get_date.rb +69 -0
- data/lib/rwiki_links/get_host_without_web.rb +23 -0
- data/lib/rwiki_links/get_html_page.rb +29 -0
- data/lib/rwiki_links/get_lang.rb +29 -0
- data/lib/rwiki_links/get_publisher.rb +58 -0
- data/lib/rwiki_links/get_title.rb +55 -0
- data/lib/rwiki_links/parse_url.rb +23 -0
- data/lib/rwiki_links/version.rb +5 -0
- data/lib/rwiki_links.rb +24 -0
- data/sig/rwiki_links.rbs +4 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7088f6222d6d2e2b2f9cdaeb64d81ee7d86477383bd12ce3a098a76c4034a371
|
4
|
+
data.tar.gz: d0d5982e3a23768daec471b4505c135aa18aa449510695003fd7925fa88f8bf6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc486a1cc41ad7591195fbc2be9694f11e5339adcc4b1f571626e15e4d7edf68482730a290f94daf6bb05c85c3762f548273194ede9dff6dcf8044954fb0bb7d
|
7
|
+
data.tar.gz: a9fd98a4c660fb220caae769237d5ef4bebc1a66f9c7f9780e39362e3cad63205e6995365adb11cd810e8bcac434e5ff3cd7a565e4955ad3e4cd4d09613118f3
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 TODO: Write your name
|
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,110 @@
|
|
1
|
+
# RWikiLinks
|
2
|
+
|
3
|
+
`RWikiLinks` is a Ruby gem designed to generate citation links for news articles. The gem extracts key information such as the article title, author, publication date, and publisher, and formats it into a citation string.
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rwiki_links'
|
13
|
+
```
|
14
|
+
|
15
|
+
Then execute:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it directly using:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
gem install rwiki_links
|
25
|
+
```
|
26
|
+
|
27
|
+
---
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Basic Example
|
32
|
+
|
33
|
+
To generate a citation for a news article, simply pass the article's URL to the `citeweb` method:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'rwiki_links'
|
37
|
+
|
38
|
+
url = 'https://www.vedomosti.ru/example'
|
39
|
+
citation = RwikiLinks.citeweb(url)
|
40
|
+
|
41
|
+
puts citation
|
42
|
+
```
|
43
|
+
|
44
|
+
### Output Example
|
45
|
+
|
46
|
+
The output will look like this:
|
47
|
+
|
48
|
+
```plaintext
|
49
|
+
{{cite web|author=Иванов, Иван|url=https://www.vedomosti.ru/example|title=Example News Title|lang=ru|website=vedomosti.ru|publisher=Ведомости|date=2025-01-25|access-date=2025-01-26}}
|
50
|
+
```
|
51
|
+
|
52
|
+
---
|
53
|
+
|
54
|
+
## Supported Websites
|
55
|
+
|
56
|
+
The gem currently works well with the following Russian news websites:
|
57
|
+
|
58
|
+
- **RIA Novosti** (`ria.ru`)
|
59
|
+
- **TASS** (`tass.ru`)
|
60
|
+
- **Kommersant** (`kommersant.ru`)
|
61
|
+
- **RBC** (`rbc.ru`)
|
62
|
+
- **Gazeta.ru** (`gazeta.ru`)
|
63
|
+
- **Lenta.ru** (`lenta.ru`)
|
64
|
+
- **Vedomosti** (`vedomosti.ru`)
|
65
|
+
- **MK.ru** (`mk.ru`)
|
66
|
+
- **RT** (`russian.rt.com`)
|
67
|
+
- **News.ru** (`news.ru`)
|
68
|
+
- etc.
|
69
|
+
|
70
|
+
---
|
71
|
+
|
72
|
+
## How It Works
|
73
|
+
|
74
|
+
RwikiLinks extracts the following information from a news article:
|
75
|
+
|
76
|
+
1. **Title**: The title of the article.
|
77
|
+
2. **Author**: The author's name (if available).
|
78
|
+
3. **Date**: The publication date.
|
79
|
+
4. **Publisher**: The name of the news website or organization.
|
80
|
+
5. **Language**: The language of the article (e.g., `ru` for Russian).
|
81
|
+
|
82
|
+
The gem uses Nokogiri to parse the HTML of the article and XPath to locate the required data.
|
83
|
+
|
84
|
+
---
|
85
|
+
|
86
|
+
## Future Plans
|
87
|
+
|
88
|
+
The first version of RwikiLinks is optimized for Russian news websites. In future updates, the gem will be expanded to support more websites globally, making it a universal tool for generating citations.
|
89
|
+
|
90
|
+
---
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
If you'd like to contribute to `RWikiLinks`, feel free to open an issue or submit a pull request. Contributions are welcome, especially for adding support for new websites or improving existing functionality.
|
95
|
+
|
96
|
+
---
|
97
|
+
|
98
|
+
## License
|
99
|
+
|
100
|
+
`RWikiLinks` is available under the MIT License. See the [LICENSE](LICENSE) file for more details.
|
101
|
+
|
102
|
+
---
|
103
|
+
|
104
|
+
## Questions?
|
105
|
+
|
106
|
+
If you have any questions or need help, feel free to open an issue on GitHub or contact the maintainers.
|
107
|
+
|
108
|
+
---
|
109
|
+
|
110
|
+
Enjoy using `RWikiLinks`! 🚀
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "memoist"
|
4
|
+
|
5
|
+
module RwikiLinks
|
6
|
+
class BuildCiteWebParams
|
7
|
+
extend Memoist
|
8
|
+
|
9
|
+
def self.call(...) = new(...).call
|
10
|
+
|
11
|
+
def initialize(url)
|
12
|
+
@url = url
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
{
|
17
|
+
url:,
|
18
|
+
website:,
|
19
|
+
title:,
|
20
|
+
lang:,
|
21
|
+
publisher:,
|
22
|
+
date:,
|
23
|
+
author:
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :url
|
30
|
+
|
31
|
+
def uri = ParseUrl.call(url)
|
32
|
+
|
33
|
+
def website = GetHostWithoutWeb.call(uri)
|
34
|
+
|
35
|
+
def page = GetHtmlPage.call(uri)
|
36
|
+
|
37
|
+
def title = GetTitle.call(page)
|
38
|
+
|
39
|
+
def lang = GetLang.call(page)
|
40
|
+
|
41
|
+
def publisher = GetPublisher.call(website)
|
42
|
+
|
43
|
+
def date = GetDate.call(page, website)
|
44
|
+
|
45
|
+
def author = GetAuthor.call(page, website)
|
46
|
+
|
47
|
+
memoize :uri, :website, :page
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RwikiLinks
|
4
|
+
class CombineCiteWeb
|
5
|
+
def self.call(...) = new(...).call
|
6
|
+
|
7
|
+
def initialize(cite_web_params)
|
8
|
+
@params = cite_web_params
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
cite_web
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :params
|
18
|
+
|
19
|
+
def cite_web
|
20
|
+
"{{cite web" \
|
21
|
+
"|author=#{params[:author]}" \
|
22
|
+
"|url=#{params[:url]}" \
|
23
|
+
"|title=#{params[:title]}" \
|
24
|
+
"|lang=#{params[:lang]}" \
|
25
|
+
"|website=#{params[:website]}" \
|
26
|
+
"|publisher=#{params[:publisher]}" \
|
27
|
+
"|date=#{params[:date]}" \
|
28
|
+
"|access-date=#{actual_date}}}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def actual_date = Time.now.strftime("%Y-%m-%d")
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RwikiLinks
|
4
|
+
class GetAuthor
|
5
|
+
def self.call(...) = new(...).call
|
6
|
+
|
7
|
+
def initialize(page, website)
|
8
|
+
@page = page
|
9
|
+
@website = website
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
swap_author_first_name_with_last_name
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
AUTHOR_XPATHS = {
|
19
|
+
"kp.ru" => "//a/span",
|
20
|
+
"vedomosti.ru" => "//div/div/header/div[2]/div[2]/div[1]/div/div/a",
|
21
|
+
"rbc.ru" => "//div[3]/meta[1]/@content",
|
22
|
+
"rambler.ru" => "//header/div/div/div/div/div/a",
|
23
|
+
"rg.ru" => "//div/div[2]/div[3]/div/div/div/div[2]/div[1]/div[1]/div[3]/div/div/a",
|
24
|
+
"gazeta.ru" => "//span/a",
|
25
|
+
"utro.ru" => "//div/a/span",
|
26
|
+
"tass.ru" => "//div/div/span",
|
27
|
+
"mk.ru" => "//div/div/ul/li/a",
|
28
|
+
"kommersant.ru" => "//div/article/footer/ul/li/span/a/span",
|
29
|
+
"svpressa.ru" => "//article/div/header/div/div/a/span",
|
30
|
+
"pnp.ru" => "//article/div[1]/div[2]/div[1]/p/a",
|
31
|
+
"360tv.ru" => "//article/footer/div/a/div/p",
|
32
|
+
"life.ru" => "/html/head/script",
|
33
|
+
"forbes.ru" => "//article/div/footer/div/div/ul/li/a/div/p",
|
34
|
+
"vc.ru" => "//script",
|
35
|
+
"lenta.ru" => "//script"
|
36
|
+
}.freeze
|
37
|
+
private_constant :AUTHOR_XPATHS
|
38
|
+
|
39
|
+
attr_reader :page, :website
|
40
|
+
|
41
|
+
def author_first_and_last_names
|
42
|
+
return "" unless AUTHOR_XPATHS.key?(website)
|
43
|
+
|
44
|
+
dig_in_existing_author_xpaths
|
45
|
+
end
|
46
|
+
|
47
|
+
def dig_in_existing_author_xpaths
|
48
|
+
page.xpath(AUTHOR_XPATHS[website]).text.strip
|
49
|
+
end
|
50
|
+
|
51
|
+
def author_splited_first_and_last_names
|
52
|
+
author_first_and_last_names.split
|
53
|
+
end
|
54
|
+
|
55
|
+
def swap_author_first_name_with_last_name
|
56
|
+
author_splited_first_and_last_names[0..1].reverse.join(", ").slice(0..30)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RwikiLinks
|
4
|
+
class GetDate
|
5
|
+
def self.call(...) = new(...).call
|
6
|
+
|
7
|
+
def initialize(page, website)
|
8
|
+
@page = page
|
9
|
+
@website = website
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
date
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
DATE_XPATHS = {
|
19
|
+
"kp.ru" => "/html/head/meta[24]/@content",
|
20
|
+
"vedomosti.ru" => "//header/div/div/time/@datetime",
|
21
|
+
"rambler.ru" => "/html/head/meta[15]/@content",
|
22
|
+
"rg.ru" => "/html/head/meta[12]/@content",
|
23
|
+
"gazeta.ru" => "//div[1]/div[1]/time/@datetime",
|
24
|
+
"utro.ru" => "//div[1]/div[1]/div/div[7]/time/@datetime",
|
25
|
+
"tass.ru" => "/html/head/meta[13]/@content",
|
26
|
+
"mk.ru" => "//main/div[1]/p/span[1]/meta[1]/@content",
|
27
|
+
"kommersant.ru" => "/html/head/meta[24]/@content",
|
28
|
+
"svpressa.ru" => "/html/head/meta[18]/@content",
|
29
|
+
"pnp.ru" => "//script",
|
30
|
+
"360tv.ru" => "/html/head/meta[21]/@content",
|
31
|
+
"life.ru" => "/html/head/meta[27]/@content",
|
32
|
+
"forbes.ru" => "//div[1]/div[1]/div[1]/time/@datetime",
|
33
|
+
"russian.rt.com" => "/html/head/meta[21]/@content",
|
34
|
+
"news.ru" => "//section/div/time/@datetime",
|
35
|
+
"ria.ru" => "//div/div/div/div/div/div[1]/div/div[1]/div[1]/div[6]",
|
36
|
+
"rbc.ru" => "//div/div[1]/div[1]/div[1]/div[1]/time/@content",
|
37
|
+
"vesti.ru" => "/html/body/div[6]/div/div/div/div/div[1]/article/@data-datepub",
|
38
|
+
"interfax.ru" => "/html/head/meta[23]/@content",
|
39
|
+
"regnum.ru" => "//div[2]/div[1]/meta[5]/@content",
|
40
|
+
"ntv.ru" => "//div/meta[6]/@content",
|
41
|
+
"1tv.ru" => "/html/head/meta[29]/@content"
|
42
|
+
}.freeze
|
43
|
+
private_constant :DATE_XPATHS
|
44
|
+
|
45
|
+
attr_reader :page, :website
|
46
|
+
|
47
|
+
def date
|
48
|
+
date_from_xpath&.length == 10 ? date_from_xpath : ""
|
49
|
+
end
|
50
|
+
|
51
|
+
def date_from_xpath
|
52
|
+
return dig_in_existing_date_xpaths if DATE_XPATHS.key?(website)
|
53
|
+
|
54
|
+
try_find_date_published
|
55
|
+
end
|
56
|
+
|
57
|
+
def dig_in_existing_date_xpaths
|
58
|
+
page.xpath(DATE_XPATHS[website]).text.slice(0..9)
|
59
|
+
end
|
60
|
+
|
61
|
+
def try_find_date_published
|
62
|
+
page.xpath("//script")
|
63
|
+
.text
|
64
|
+
.match(/datePublished":"([^T]+)T/)
|
65
|
+
&.captures
|
66
|
+
&.first
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RwikiLinks
|
4
|
+
class GetHostWithoutWeb
|
5
|
+
def self.call(...) = new(...).call
|
6
|
+
|
7
|
+
def initialize(uri)
|
8
|
+
@uri = uri
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
host_without_web
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :uri
|
18
|
+
|
19
|
+
def host_without_web
|
20
|
+
uri.host.sub(/^www\./, "")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "nokogiri"
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
6
|
+
|
7
|
+
module RwikiLinks
|
8
|
+
class GetHtmlPage
|
9
|
+
def self.call(...) = new(...).call
|
10
|
+
|
11
|
+
def initialize(uri)
|
12
|
+
@uri = uri
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
html_from_uri_response_body
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :uri
|
22
|
+
|
23
|
+
def html_from_uri_response_body
|
24
|
+
Nokogiri::HTML(response.body)
|
25
|
+
end
|
26
|
+
|
27
|
+
def response = Net::HTTP.get_response(uri)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RwikiLinks
|
4
|
+
class GetLang
|
5
|
+
def self.call(...) = new(...).call
|
6
|
+
|
7
|
+
def initialize(page)
|
8
|
+
@page = page
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
lang
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
LANG_XPATH = "/html/@lang"
|
18
|
+
private_constant :LANG_XPATH
|
19
|
+
|
20
|
+
attr_reader :page
|
21
|
+
|
22
|
+
def lang
|
23
|
+
page.xpath(LANG_XPATH)
|
24
|
+
.text
|
25
|
+
.split("-")
|
26
|
+
.first || ""
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RwikiLinks
|
4
|
+
class GetPublisher
|
5
|
+
def self.call(...) = new(...).call
|
6
|
+
|
7
|
+
def initialize(website)
|
8
|
+
@website = website
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
publisher
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
PUBLISHERS = {
|
18
|
+
"ria.ru" => "РИА Новости",
|
19
|
+
"pnp.ru" => "Парламентская газета",
|
20
|
+
"russian.rt.com" => "RT",
|
21
|
+
"1tv.ru" => "Первый канал",
|
22
|
+
"svpressa.ru" => "Свободная Пресса",
|
23
|
+
"ntv.ru" => "НТВ",
|
24
|
+
"mk.ru" => "Московский Комсомолец",
|
25
|
+
"rg.ru" => "Российская Газета",
|
26
|
+
"news.ru" => "NEWS.ru",
|
27
|
+
"aif.ru" => "Аргументы и Факты",
|
28
|
+
"gazeta.ru" => "Газета.Ru",
|
29
|
+
"tass.ru" => "ТАСС",
|
30
|
+
"kp.ru" => "Комсомольская Правда",
|
31
|
+
"rbc.ru" => "РБК",
|
32
|
+
"vc.ru" => "VC.ru",
|
33
|
+
"vedomosti.ru" => "Ведомости"
|
34
|
+
}.freeze
|
35
|
+
private_constant :PUBLISHERS
|
36
|
+
|
37
|
+
EXCEPTIONS = {
|
38
|
+
"bbc.co.uk" => "BBC",
|
39
|
+
"theguardian.com" => "The Guardian",
|
40
|
+
"nytimes.com" => "The New York Times"
|
41
|
+
}.freeze
|
42
|
+
private_constant :EXCEPTIONS
|
43
|
+
|
44
|
+
attr_reader :website
|
45
|
+
|
46
|
+
def publisher
|
47
|
+
PUBLISHERS[website] || publisher_from_host
|
48
|
+
end
|
49
|
+
|
50
|
+
def publisher_from_host
|
51
|
+
return EXCEPTIONS[website] if EXCEPTIONS.key?(website)
|
52
|
+
|
53
|
+
website.sub(/^the/, "")
|
54
|
+
.sub(/\..*$/, "")
|
55
|
+
.capitalize
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RwikiLinks
|
4
|
+
class GetTitle
|
5
|
+
def self.call(...) = new(...).call
|
6
|
+
|
7
|
+
def initialize(page)
|
8
|
+
@page = page
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
cleanup_title
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
TITLE_XPATH = "//title"
|
18
|
+
private_constant :TITLE_XPATH
|
19
|
+
|
20
|
+
TITLE_CLEANUP_REGEX = %r{
|
21
|
+
-\sNEWS |
|
22
|
+
\sна\svc\.ru |
|
23
|
+
-\sРамблер/новости |
|
24
|
+
\s::\s |
|
25
|
+
—\sЛичный\sопыт\sна\svc\.ru |
|
26
|
+
-\sРИА\sНовости |
|
27
|
+
\s\|\s |
|
28
|
+
—\sРБК |
|
29
|
+
-\sKP\.RU |
|
30
|
+
:\sLenta\.ru |
|
31
|
+
–\sКоммерсантъ |
|
32
|
+
-\sИА\sREGNUM |
|
33
|
+
-\sСвободная\sПресса |
|
34
|
+
\s// |
|
35
|
+
\.\sНовости |
|
36
|
+
-\sПарламентская\sгазета |
|
37
|
+
—\sРТ\sна\sрусском |
|
38
|
+
-\sМК |
|
39
|
+
-\sРоссийская\sгазета |
|
40
|
+
-\sВедомости |
|
41
|
+
-\sГазета\.Ru
|
42
|
+
}x
|
43
|
+
private_constant :TITLE_CLEANUP_REGEX
|
44
|
+
|
45
|
+
attr_reader :page
|
46
|
+
|
47
|
+
def cleanup_title
|
48
|
+
title.gsub(TITLE_CLEANUP_REGEX, "").strip
|
49
|
+
end
|
50
|
+
|
51
|
+
def title
|
52
|
+
page.xpath(TITLE_XPATH).text
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open-uri"
|
4
|
+
|
5
|
+
module RwikiLinks
|
6
|
+
class ParseUrl
|
7
|
+
def self.call(...) = new(...).call
|
8
|
+
|
9
|
+
def initialize(url)
|
10
|
+
@url = url
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
uri
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :url
|
20
|
+
|
21
|
+
def uri = URI.parse(url)
|
22
|
+
end
|
23
|
+
end
|
data/lib/rwiki_links.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require_relative "rwiki_links/version"
|
7
|
+
|
8
|
+
module RwikiLinks
|
9
|
+
autoload :CombineCiteWeb, "rwiki_links/combine_cite_web.rb"
|
10
|
+
autoload :BuildCiteWebParams, "rwiki_links/build_cite_web_params.rb"
|
11
|
+
autoload :ParseUrl, "rwiki_links/parse_url.rb"
|
12
|
+
autoload :GetHostWithoutWeb, "rwiki_links/get_host_without_web.rb"
|
13
|
+
autoload :GetHtmlPage, "rwiki_links/get_html_page.rb"
|
14
|
+
autoload :GetTitle, "rwiki_links/get_title.rb"
|
15
|
+
autoload :GetLang, "rwiki_links/get_lang.rb"
|
16
|
+
autoload :GetPublisher, "rwiki_links/get_publisher.rb"
|
17
|
+
autoload :GetDate, "rwiki_links/get_date.rb"
|
18
|
+
autoload :GetAuthor, "rwiki_links/get_author.rb"
|
19
|
+
|
20
|
+
def self.citeweb(url)
|
21
|
+
cite_web_params = BuildCiteWebParams.call(url)
|
22
|
+
CombineCiteWeb.call(cite_web_params)
|
23
|
+
end
|
24
|
+
end
|
data/sig/rwiki_links.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rwiki_links
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Khamitskiy Vladislav
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-01-26 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.15'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
description: This gem helps generate citation links for Wikipedia in the cite web
|
28
|
+
format.
|
29
|
+
email:
|
30
|
+
- vladislaviktorovic@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/rwiki_links.rb
|
43
|
+
- lib/rwiki_links/build_cite_web_params.rb
|
44
|
+
- lib/rwiki_links/combine_cite_web.rb
|
45
|
+
- lib/rwiki_links/get_author.rb
|
46
|
+
- lib/rwiki_links/get_date.rb
|
47
|
+
- lib/rwiki_links/get_host_without_web.rb
|
48
|
+
- lib/rwiki_links/get_html_page.rb
|
49
|
+
- lib/rwiki_links/get_lang.rb
|
50
|
+
- lib/rwiki_links/get_publisher.rb
|
51
|
+
- lib/rwiki_links/get_title.rb
|
52
|
+
- lib/rwiki_links/parse_url.rb
|
53
|
+
- lib/rwiki_links/version.rb
|
54
|
+
- sig/rwiki_links.rbs
|
55
|
+
homepage: https://github.com/khamitskiy-vlad/rwiki_links#readme
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata:
|
59
|
+
homepage_uri: https://github.com/khamitskiy-vlad/rwiki_links#readme
|
60
|
+
source_code_uri: https://github.com/khamitskiy-vlad/rwiki_links
|
61
|
+
changelog_uri: https://github.com/khamitskiy-vlad/rwiki_links/blob/main/CHANGELOG.md
|
62
|
+
keywords: wikipedia, wiki, citation, cite-web, ruby, gem, link
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 3.1.0
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubygems_version: 3.5.11
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: A gem for generating Wikipedia citation links.
|
82
|
+
test_files: []
|