comicinfo-grand_comics_database 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/.ruby-version +1 -0
- data/CHANGELOG.md +12 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.md +21 -0
- data/README.md +50 -0
- data/Rakefile +10 -0
- data/lib/comicinfo/grand_comics_database/client.rb +42 -0
- data/lib/comicinfo/grand_comics_database/credit.rb +43 -0
- data/lib/comicinfo/grand_comics_database/errors.rb +26 -0
- data/lib/comicinfo/grand_comics_database/found_issue.rb +101 -0
- data/lib/comicinfo/grand_comics_database/key_date.rb +26 -0
- data/lib/comicinfo/grand_comics_database/series_name.rb +23 -0
- data/lib/comicinfo/grand_comics_database/version.rb +5 -0
- data/lib/comicinfo/grand_comics_database.rb +101 -0
- data/sig/comicinfo/grand_comics_database.rbs +6 -0
- metadata +90 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 027cc37f653a65869b3b1a4a7d4e2738c3be228025916c2ee95fb8c51ebcaf9a
|
|
4
|
+
data.tar.gz: 7065ff00bcb79c615cfe04250e6b3a97a0a5a8778ce1d52e70075e4fb0926e1a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5de5fcaf2a36be675f32ca86350741fcad8b8c32e7134499d9c772757a607b181e4d23f2af6c4a77414e89c5d3f2ac72970a90285e1e277d213633e70dcac1a9
|
|
7
|
+
data.tar.gz: fd0ccb9ee38032f5ca994cf91fc41090441a6bbb3f6f129d8e8223480526bd3ee971cb2502a4425b1d8f67904adaef32cea6e06f583bddcc7418cd96a1644c37
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4.0.9
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `ComicInfo::GrandComicsDatabase`, a metadata source for the [Grand Comics Database](https://www.comics.org/). `matches(issue)` needs a series, number and year, and finds the issue with the comic's number in every series from that year whose name contains the comic's series, exact series names first. `issue(match)` reads the picked issue into a `ComicInfo::Issue`: series, number, title, year and month, indicia publisher, summary, credits by role, characters, genres, cover artist, and its GCD page
|
|
12
|
+
- `ComicInfo::GrandComicsDatabase::HTTPError` and `ComicInfo::GrandComicsDatabase::InvalidIssueIDError`: an HTTP error status, or a match ID that isn't a GCD issue ID
|
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
|
+
veganstraightedge@gmail.com.
|
|
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.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shane Becker
|
|
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,50 @@
|
|
|
1
|
+
# comicinfo-grand_comics_database
|
|
2
|
+
|
|
3
|
+
Looks up comic details in the [Grand Comics Database](https://www.comics.org/) (GCD), for the [comicinfo](https://github.com/veganstraightedge/comicinfo) gem.
|
|
4
|
+
|
|
5
|
+
`ComicInfo::GrandComicsDatabase` is a metadata source: it searches the GCD for an issue, and returns what the GCD knows about the one picked as a `ComicInfo::Issue`. See [Looking Up Details in Online Databases](https://github.com/veganstraightedge/comicinfo/blob/main/doc/metadata-sources.md).
|
|
6
|
+
|
|
7
|
+
It's the Ruby counterpart of [ComicInfoGrandComicsDatabase.swift](https://github.com/veganstraightedge/ComicInfoGrandComicsDatabase.swift).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'comicinfo-grand_comics_database'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
require 'comicinfo/grand_comics_database'
|
|
19
|
+
|
|
20
|
+
grand_comics_database = ComicInfo::GrandComicsDatabase.new user_agent: 'MyApp/1.0'
|
|
21
|
+
|
|
22
|
+
issue = ComicInfo.load 'path/to/ComicInfo.xml'
|
|
23
|
+
matches = grand_comics_database.matches issue # best first
|
|
24
|
+
found = grand_comics_database.issue matches[0] # after a person picks one
|
|
25
|
+
updated = issue.with_blanks_filled_from found
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- `matches` needs a Series, a Number and a Year; `missing_details` says so when any is blank. The GCD matches series names by substring and lists them alphabetically, so the year, the year the series began, narrows them to the one wanted.
|
|
29
|
+
- It finds the issue with the comic's number in every series from that year whose name contains the comic's series, and ranks series named exactly as the comic's first. A match's `series` leaves out the GCD's " (2012 series)" suffix; its `heading` keeps it, and its `details` are the issue's publication date, such as "March 2012".
|
|
30
|
+
- `issue` reads the issue: series, number, title (its own, or its first comic story's), year and month, indicia publisher, summary (its comic stories' synopses), credits by role, characters and genres from its comic stories, the cover artist from its cover, and the issue's GCD page as its web link.
|
|
31
|
+
- A request the GCD refuses raises `ComicInfo::GrandComicsDatabase::HTTPError` (with its `status`), and a match ID that isn't a GCD issue ID raises `ComicInfo::GrandComicsDatabase::InvalidIssueIDError` (with its `id`). Both are `ComicInfo::GrandComicsDatabase::Error`s.
|
|
32
|
+
|
|
33
|
+
## Terms
|
|
34
|
+
|
|
35
|
+
- The GCD's API needs no key.
|
|
36
|
+
- The GCD's data is licensed [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/): whatever shows it must credit and link to the Grand Comics Database (`grand_comics_database.name`, `grand_comics_database.home_url`), and share what's made from it under the same license.
|
|
37
|
+
- `user_agent:` names your app to the GCD.
|
|
38
|
+
|
|
39
|
+
## Development
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
bin/setup # bundle install
|
|
43
|
+
bundle exec rake # specs and RuboCop
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The specs answer every request from a local server with a recorded GCD response from `spec/fixtures/`, so they need no network.
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
[MIT](LICENSE.md)
|
data/Rakefile
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'uri'
|
|
4
|
+
require_relative 'errors'
|
|
5
|
+
|
|
6
|
+
module ComicInfo
|
|
7
|
+
class GrandComicsDatabase
|
|
8
|
+
# Calls the Grand Comics Database API, which needs no key.
|
|
9
|
+
#
|
|
10
|
+
# Results are the GCD's JSON, parsed with symbol keys. See https://www.comics.org/api/
|
|
11
|
+
class Client
|
|
12
|
+
def initialize base_url:, user_agent:
|
|
13
|
+
@base_url = base_url
|
|
14
|
+
@user_agent = user_agent
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# The issues numbered number, in series whose names contain series, from series that began in year.
|
|
18
|
+
#
|
|
19
|
+
# Only the first page of results is read.
|
|
20
|
+
def find_issues number:, series:, year:
|
|
21
|
+
get('series', 'name', series, 'issue', number, 'year', year)[:results]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# One issue, stories and all
|
|
25
|
+
def issue(id) = get 'issue', id
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# Calls one API resource, its path in segments, each escaped on its own so a "/" in a series name stays in it
|
|
30
|
+
def get *segments
|
|
31
|
+
path = segments.map { URI.encode_uri_component it.to_s }.join('/')
|
|
32
|
+
uri = URI.join @base_url, "#{path}/"
|
|
33
|
+
uri.query = URI.encode_www_form format: 'json'
|
|
34
|
+
|
|
35
|
+
response = Net::HTTP.get_response uri, 'User-Agent' => @user_agent
|
|
36
|
+
raise HTTPError, response.code.to_i unless response.is_a? Net::HTTPOK
|
|
37
|
+
|
|
38
|
+
JSON.parse response.body, symbolize_names: true
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module ComicInfo
|
|
2
|
+
class GrandComicsDatabase
|
|
3
|
+
# A GCD credit string, such as "Fiona Staples (credited) (signed as FS); Brian K. Vaughan [as BKV]".
|
|
4
|
+
#
|
|
5
|
+
# Characters are written the same way, such as "Alana (featured) (first appearance of Alana); Lying Cat".
|
|
6
|
+
class Credit
|
|
7
|
+
NOTE_ENDS = [')', ']'].freeze
|
|
8
|
+
NOTE_STARTS = ['(', '['].freeze
|
|
9
|
+
NOBODY = 'None'.freeze
|
|
10
|
+
SEPARATOR = ';'.freeze
|
|
11
|
+
UNCERTAIN = '?'.freeze
|
|
12
|
+
|
|
13
|
+
def initialize credit
|
|
14
|
+
@credit = credit.to_s
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# The names, in order. Notes in parentheses and brackets are left out, at any depth,
|
|
18
|
+
# and so are "None" and names marked uncertain with "?".
|
|
19
|
+
def names
|
|
20
|
+
outside_notes.split(SEPARATOR)
|
|
21
|
+
.map(&:strip)
|
|
22
|
+
.reject { it.empty? || it == NOBODY || it.end_with?(UNCERTAIN) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
# The credit with its notes left out
|
|
28
|
+
def outside_notes
|
|
29
|
+
depth = 0
|
|
30
|
+
|
|
31
|
+
@credit.each_char.with_object(+'') do |character, outside|
|
|
32
|
+
if NOTE_STARTS.include? character
|
|
33
|
+
depth += 1
|
|
34
|
+
elsif NOTE_ENDS.include? character
|
|
35
|
+
depth = [depth - 1, 0].max
|
|
36
|
+
elsif depth.zero?
|
|
37
|
+
outside << character
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module ComicInfo
|
|
2
|
+
class GrandComicsDatabase
|
|
3
|
+
# Why a Grand Comics Database request failed
|
|
4
|
+
class Error < ComicInfo::Error; end
|
|
5
|
+
|
|
6
|
+
# The GCD answered with an HTTP error status, such as 404 or 503
|
|
7
|
+
class HTTPError < Error
|
|
8
|
+
attr_reader :status
|
|
9
|
+
|
|
10
|
+
def initialize status
|
|
11
|
+
@status = status
|
|
12
|
+
super("The Grand Comics Database answered with HTTP status #{status}.")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# A match's ID isn't a GCD issue ID, which is a number
|
|
17
|
+
class InvalidIssueIDError < Error
|
|
18
|
+
attr_reader :id
|
|
19
|
+
|
|
20
|
+
def initialize id
|
|
21
|
+
@id = id
|
|
22
|
+
super("The Grand Comics Database has no issue with the ID #{id}.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require 'nokogiri'
|
|
2
|
+
require_relative 'credit'
|
|
3
|
+
require_relative 'key_date'
|
|
4
|
+
require_relative 'series_name'
|
|
5
|
+
|
|
6
|
+
module ComicInfo
|
|
7
|
+
class GrandComicsDatabase
|
|
8
|
+
# A Grand Comics Database issue, as a ComicInfo::Issue.
|
|
9
|
+
#
|
|
10
|
+
# Credits, characters, genres and the summary come from the issue's comic stories; the cover artist
|
|
11
|
+
# is whoever pencilled its cover.
|
|
12
|
+
#
|
|
13
|
+
# The issue is built from ComicInfo XML with only the fields the GCD knows, so
|
|
14
|
+
# ComicInfo::Issue#with_blanks_filled_from keeps what a comic already has.
|
|
15
|
+
class FoundIssue
|
|
16
|
+
COMIC_STORY = 'comic story'.freeze
|
|
17
|
+
COVER = 'cover'.freeze
|
|
18
|
+
|
|
19
|
+
# - id: the GCD's ID for the issue, for its page on the GCD's site
|
|
20
|
+
# - issue: the GCD's issue detail
|
|
21
|
+
def initialize id:, issue:
|
|
22
|
+
@id = id
|
|
23
|
+
@issue = issue
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_issue
|
|
27
|
+
characters = everyone(stories.map { it[:characters] })
|
|
28
|
+
# Genres are separated by semicolons, as credits are, such as "fantasy; science fiction"
|
|
29
|
+
genres = Credit.new(stories.first&.dig(:genre)).names
|
|
30
|
+
|
|
31
|
+
ComicInfo.load(xml)
|
|
32
|
+
.with_characters(characters)
|
|
33
|
+
.with_genres(genres)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
# ComicInfo XML with every field the GCD knows, by element name
|
|
39
|
+
def xml
|
|
40
|
+
document = Nokogiri::XML::Document.new
|
|
41
|
+
root = document.create_element 'ComicInfo'
|
|
42
|
+
|
|
43
|
+
fields.each { |element, value| root.add_child document.create_element(element, value.to_s) }
|
|
44
|
+
document.root = root
|
|
45
|
+
|
|
46
|
+
document.to_xml
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def fields
|
|
50
|
+
key_date = KeyDate.new @issue[:key_date]
|
|
51
|
+
|
|
52
|
+
{
|
|
53
|
+
'Colorist' => credited(stories, :colors),
|
|
54
|
+
'CoverArtist' => credited(covers, :pencils),
|
|
55
|
+
'Editor' => credited(stories, :editing),
|
|
56
|
+
'Inker' => credited(stories, :inks),
|
|
57
|
+
'Letterer' => credited(stories, :letters),
|
|
58
|
+
'Month' => key_date.month,
|
|
59
|
+
'Number' => present(@issue[:number]),
|
|
60
|
+
'Penciller' => credited(stories, :pencils),
|
|
61
|
+
'Publisher' => present(@issue[:indicia_publisher]),
|
|
62
|
+
'Series' => present(SeriesName.new(@issue[:series_name]).name),
|
|
63
|
+
'Summary' => synopses,
|
|
64
|
+
'Title' => title,
|
|
65
|
+
'Web' => "https://www.comics.org/issue/#{@id}/",
|
|
66
|
+
'Writer' => credited(stories, :script),
|
|
67
|
+
'Year' => key_date.year
|
|
68
|
+
}.compact
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def covers = stories_of_type COVER
|
|
72
|
+
def stories = stories_of_type COMIC_STORY
|
|
73
|
+
|
|
74
|
+
def stories_of_type(type) = @issue[:story_set].to_a.select { it[:type] == type }
|
|
75
|
+
|
|
76
|
+
# Everyone the stories credit in field, each once, joined with commas; nil when no one is
|
|
77
|
+
def credited stories, field
|
|
78
|
+
credits = stories.map { it[field] }
|
|
79
|
+
people = everyone credits
|
|
80
|
+
|
|
81
|
+
people.join ', ' unless people.empty?
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Everyone the credit strings name, each once, in order
|
|
85
|
+
def everyone(credits) = credits.flat_map { Credit.new(it).names }.uniq
|
|
86
|
+
|
|
87
|
+
# The comic stories' synopses, joined, or nil when none has one
|
|
88
|
+
def synopses = present(stories.filter_map { present it[:synopsis] }.join(' '))
|
|
89
|
+
|
|
90
|
+
# The issue's own title, or its first titled story's: most issues have none of their own
|
|
91
|
+
def title = present(@issue[:title]) || stories.lazy.filter_map { present it[:title] }.first
|
|
92
|
+
|
|
93
|
+
# The text, trimmed, or nil when it's blank
|
|
94
|
+
def present text
|
|
95
|
+
trimmed = text.to_s.strip
|
|
96
|
+
|
|
97
|
+
trimmed unless trimmed.empty?
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module ComicInfo
|
|
2
|
+
class GrandComicsDatabase
|
|
3
|
+
# A key date such as "2012-03-00", as a year and month.
|
|
4
|
+
#
|
|
5
|
+
# The GCD writes 00 for a month or day it doesn't know. The day is left out.
|
|
6
|
+
class KeyDate
|
|
7
|
+
def initialize text
|
|
8
|
+
@parts = text.to_s.split '-'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# The year, or nil when there isn't one
|
|
12
|
+
def year
|
|
13
|
+
year = Integer @parts[0], 10, exception: false if @parts.length >= 2
|
|
14
|
+
|
|
15
|
+
year if year&.between? 1000, 9999
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# The month, 1 to 12, or nil when there isn't one
|
|
19
|
+
def month
|
|
20
|
+
month = Integer @parts[1], 10, exception: false if @parts.length >= 2
|
|
21
|
+
|
|
22
|
+
month if month&.between? 1, 12
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module ComicInfo
|
|
2
|
+
class GrandComicsDatabase
|
|
3
|
+
# A series name as the GCD writes it, such as "Saga (2012 series)"
|
|
4
|
+
class SeriesName
|
|
5
|
+
SUFFIX_END = ' series)'.freeze
|
|
6
|
+
SUFFIX_START = ' ('.freeze
|
|
7
|
+
|
|
8
|
+
def initialize name
|
|
9
|
+
@name = name.to_s
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# The name without the GCD's " (2012 series)" suffix
|
|
13
|
+
def name
|
|
14
|
+
return @name unless @name.end_with? SUFFIX_END
|
|
15
|
+
|
|
16
|
+
suffix_start = @name.rindex SUFFIX_START
|
|
17
|
+
return @name unless suffix_start
|
|
18
|
+
|
|
19
|
+
@name[...suffix_start]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require 'comicinfo'
|
|
2
|
+
require 'uri'
|
|
3
|
+
require_relative 'grand_comics_database/client'
|
|
4
|
+
require_relative 'grand_comics_database/errors'
|
|
5
|
+
require_relative 'grand_comics_database/found_issue'
|
|
6
|
+
require_relative 'grand_comics_database/series_name'
|
|
7
|
+
require_relative 'grand_comics_database/version'
|
|
8
|
+
|
|
9
|
+
module ComicInfo
|
|
10
|
+
# Looks up comic details in the Grand Comics Database, https://www.comics.org/
|
|
11
|
+
#
|
|
12
|
+
# grand_comics_database = ComicInfo::GrandComicsDatabase.new user_agent: 'MyApp/1.0'
|
|
13
|
+
# matches = grand_comics_database.matches issue
|
|
14
|
+
# found = grand_comics_database.issue matches.first
|
|
15
|
+
# updated = issue.with_blanks_filled_from found
|
|
16
|
+
#
|
|
17
|
+
# The GCD's data is licensed CC BY-SA 4.0: whatever shows it credits and links to the GCD.
|
|
18
|
+
# Its API needs no key.
|
|
19
|
+
class GrandComicsDatabase
|
|
20
|
+
BASE_URL = 'https://www.comics.org/api/'.freeze
|
|
21
|
+
|
|
22
|
+
# - user_agent: names the app, such as "MyApp/1.0"
|
|
23
|
+
# - base_url: where the API is, for testing against a server of your own
|
|
24
|
+
def initialize user_agent:, base_url: BASE_URL
|
|
25
|
+
@client = Client.new(base_url:, user_agent:)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def name = 'Grand Comics Database'
|
|
29
|
+
def home_url = 'https://www.comics.org/'
|
|
30
|
+
|
|
31
|
+
# What the issue still needs before it can be searched for, or nil.
|
|
32
|
+
#
|
|
33
|
+
# The GCD matches series names by substring and lists them alphabetically, so without the year
|
|
34
|
+
# the series wanted is rarely among the results.
|
|
35
|
+
def missing_details issue
|
|
36
|
+
return if present(issue.series) && present(issue.number) && issue.year.to_i.positive?
|
|
37
|
+
|
|
38
|
+
'The Grand Comics Database needs a Series, a Number and a Year to search for.'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# The issues with the issue's number in every series from its year whose name contains its series, best first.
|
|
42
|
+
#
|
|
43
|
+
# The GCD writes no cover date in its search results, only a publication date such as "March 2012",
|
|
44
|
+
# so matches are ranked by series name alone.
|
|
45
|
+
def matches issue
|
|
46
|
+
found = client.find_issues number: issue.number, series: issue.series, year: issue.year
|
|
47
|
+
matches = found.filter_map { match_for it }
|
|
48
|
+
|
|
49
|
+
issue.rank matches
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Everything the GCD knows about the match's issue, as a ComicInfo::Issue
|
|
53
|
+
def issue match
|
|
54
|
+
id = Integer match.id, 10, exception: false
|
|
55
|
+
raise InvalidIssueIDError, match.id unless id
|
|
56
|
+
|
|
57
|
+
found = client.issue id
|
|
58
|
+
|
|
59
|
+
FoundIssue.new(id:, issue: found).to_issue
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
attr_reader :client
|
|
65
|
+
|
|
66
|
+
# One issue from the search, as a match, or nil when its ID can't be read
|
|
67
|
+
def match_for found
|
|
68
|
+
id = issue_id found[:api_url]
|
|
69
|
+
return unless id
|
|
70
|
+
|
|
71
|
+
series_name = found[:series_name].to_s
|
|
72
|
+
descriptor = found[:descriptor].to_s
|
|
73
|
+
|
|
74
|
+
Match.new details: present(found[:publication_date]),
|
|
75
|
+
heading: "#{series_name} ##{descriptor}",
|
|
76
|
+
id: id.to_s,
|
|
77
|
+
number: present(descriptor),
|
|
78
|
+
series: SeriesName.new(series_name).name,
|
|
79
|
+
site_url: site_url(id)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# The ID at the end of an issue's API address, such as https://www.comics.org/api/issue/911609/?format=json
|
|
83
|
+
def issue_id api_url
|
|
84
|
+
last_segment = URI(api_url.to_s).path.split('/').last
|
|
85
|
+
|
|
86
|
+
Integer last_segment, 10, exception: false
|
|
87
|
+
rescue URI::InvalidURIError
|
|
88
|
+
nil
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# The issue's page on the GCD's site
|
|
92
|
+
def site_url(id) = "https://www.comics.org/issue/#{id}/"
|
|
93
|
+
|
|
94
|
+
# The text, trimmed, or nil when it's blank
|
|
95
|
+
def present text
|
|
96
|
+
trimmed = text.to_s.strip
|
|
97
|
+
|
|
98
|
+
trimmed unless trimmed.empty?
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: comicinfo-grand_comics_database
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Shane Becker
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: comicinfo
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.3'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.3'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: nokogiri
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.19.7
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 1.19.7
|
|
40
|
+
description: |
|
|
41
|
+
A metadata source for the comicinfo gem: searches the Grand Comics Database for an issue,
|
|
42
|
+
and returns what the Grand Comics Database knows about the one picked as a ComicInfo::Issue
|
|
43
|
+
email:
|
|
44
|
+
- veganstraightedge@gmail.com
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".ruby-version"
|
|
50
|
+
- CHANGELOG.md
|
|
51
|
+
- CODE_OF_CONDUCT.md
|
|
52
|
+
- LICENSE.md
|
|
53
|
+
- README.md
|
|
54
|
+
- Rakefile
|
|
55
|
+
- lib/comicinfo/grand_comics_database.rb
|
|
56
|
+
- lib/comicinfo/grand_comics_database/client.rb
|
|
57
|
+
- lib/comicinfo/grand_comics_database/credit.rb
|
|
58
|
+
- lib/comicinfo/grand_comics_database/errors.rb
|
|
59
|
+
- lib/comicinfo/grand_comics_database/found_issue.rb
|
|
60
|
+
- lib/comicinfo/grand_comics_database/key_date.rb
|
|
61
|
+
- lib/comicinfo/grand_comics_database/series_name.rb
|
|
62
|
+
- lib/comicinfo/grand_comics_database/version.rb
|
|
63
|
+
- sig/comicinfo/grand_comics_database.rbs
|
|
64
|
+
homepage: https://github.com/veganstraightedge/comicinfo-grand_comics_database
|
|
65
|
+
licenses:
|
|
66
|
+
- MIT
|
|
67
|
+
metadata:
|
|
68
|
+
allowed_push_host: https://rubygems.org
|
|
69
|
+
homepage_uri: https://github.com/veganstraightedge/comicinfo-grand_comics_database
|
|
70
|
+
source_code_uri: https://github.com/veganstraightedge/comicinfo-grand_comics_database
|
|
71
|
+
changelog_uri: https://github.com/veganstraightedge/comicinfo-grand_comics_database/blob/main/CHANGELOG.md
|
|
72
|
+
rubygems_mfa_required: 'true'
|
|
73
|
+
rdoc_options: []
|
|
74
|
+
require_paths:
|
|
75
|
+
- lib
|
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: 4.0.9
|
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
requirements: []
|
|
87
|
+
rubygems_version: 4.0.20
|
|
88
|
+
specification_version: 4
|
|
89
|
+
summary: Looks up comic details in the Grand Comics Database, for the comicinfo gem
|
|
90
|
+
test_files: []
|