comicinfo 1.0.0 → 2.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 +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +52 -1
- data/README.md +99 -16
- data/doc/development.md +39 -29
- data/lib/comicinfo/enums.rb +1 -0
- data/lib/comicinfo/filename_template.rb +103 -0
- data/lib/comicinfo/issue.rb +252 -76
- data/lib/comicinfo/page.rb +10 -0
- data/lib/comicinfo/version.rb +1 -1
- data/lib/comicinfo.rb +1 -0
- metadata +6 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf3f8e761a19b3c54cba4a86714dbe1ee56de99fa246d631f69a71e7e80960e6
|
|
4
|
+
data.tar.gz: 8a4f1f896f244b4460e8b94c8d9659065e2c150ec5096e2abe26e9362b95d3f9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f0d20e28c25196f01aa19619d567cfee972a720e3836091d350af7199b5ca1938f22221de62a902a98ad417844fbb6d19fbaf02600e647e770c4b37289d5f8ec
|
|
7
|
+
data.tar.gz: 7ca01c77acae36624abbc261b3365c1486383e4c893dfe319c02d79ea2a78a44f9e3526e5563377183ed81cb117e6086f1d2d3a03038d16062a328bf75723c3d
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
4.0.9
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,57 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [2.1.0] - 2026-11-19
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `ComicInfo::Issue#rearranging_pages(order)`: a copy of the issue with its `<Page>` entries and `PageCount` brought up to date after page images were reordered, deleted, or added. Entries follow their image to its new index, deleted pages lose theirs, and new pages get a default entry when the issue has page entries at all
|
|
14
|
+
- `ComicInfo::Issue#page_type(at:)` and `ComicInfo::Issue#setting_page_type(type, at:)`: read and set the type of a page image by its index. A page with no `<Page>` entry is a Story page; setting another type on it adds an entry, and an existing entry keeps its other details
|
|
15
|
+
- `ComicInfo::Page#with_image(image)` and `ComicInfo::Page#with_type(type)`: a copy of a page entry pointing at another image, or with another type
|
|
16
|
+
- `ComicInfo::Issue#filename(template:)`: a file name for the issue from a template such as `{series} #{number} ({year})` ("Saga #1 (2012)"). Missing values are left out along with the decoration around them, `/` and `:` in values become `-`, and `{number:3}` pads the issue number with zeros ("Saga #001")
|
|
17
|
+
- `ComicInfo::Issue#page_filename(template:, page:, of:)`: a file name for one page image, from a template such as `page_{page:3}` or `{series}_{number:3}_{page:4}`. The page number is always at least as wide as the page count, and a template without one gets it appended, so the names keep pages apart and in order
|
|
18
|
+
- `ComicInfo::FilenameTemplate`, which does the filling in, with the tokens it knows in `TOKENS` and `PAGE_TOKENS`
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- Bump Ruby version from 3.4.6 to 4.0.9 (`.ruby-version`, `required_ruby_version`, rubocop `TargetRubyVersion`, CI matrix)
|
|
22
|
+
- Update RuboCop to 1.87.0 (supports Ruby 4.0 `TargetRubyVersion`)
|
|
23
|
+
- Corrected the README and `doc/development.md` where they described methods that do not exist (`#character`, `#team`) or the wrong return types (`#genre` returns an array, `CommunityRating` is a `Float`), and dropped already-shipped features from the future list
|
|
24
|
+
|
|
25
|
+
## [2.0.0] - 2025-11-10
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
- **XML Generation**: Complete ComicInfo XML writing functionality
|
|
29
|
+
- `ComicInfo::Issue#to_xml` method for generating XML strings
|
|
30
|
+
- `ComicInfo::Issue#save(file_path_or_io)` method for writing to files or IO objects
|
|
31
|
+
- Valid ComicInfo v2.0 compliant XML output with UTF-8 encoding and schema namespaces
|
|
32
|
+
- Only includes non-default/non-empty values for clean XML output
|
|
33
|
+
- Proper XML entity escaping for special characters
|
|
34
|
+
- Full Pages section generation with all page attributes
|
|
35
|
+
- Round-trip consistency (load -> save -> load maintains data integrity)
|
|
36
|
+
|
|
37
|
+
### Changed - BREAKING
|
|
38
|
+
- **Multi-value field method naming**: Changed from singular/plural pattern to plural/raw_data pattern
|
|
39
|
+
- Plural methods (e.g., `genres`, `characters`) now return arrays
|
|
40
|
+
- Raw data methods (e.g., `genres_raw_data`, `characters_raw_data`) return original comma-separated strings
|
|
41
|
+
- Singular schema elements now alias to plural methods (e.g., `genre` aliases to `genres`)
|
|
42
|
+
- Export hashes include both raw data keys and _raw_data keys with duplicate values for backward compatibility
|
|
43
|
+
- This affects: `genre`/`genres`, `character`/`characters`, `team`/`teams`, `location`/`locations`, `story_arc`/`story_arcs`, `story_arc_number`/`story_arc_numbers`
|
|
44
|
+
|
|
45
|
+
### Migration Guide
|
|
46
|
+
- Replace `.genre` calls with `.genres` (now returns array) or `.genres_raw_data` (for string)
|
|
47
|
+
- Replace `.character` calls with `.characters_raw_data` (for string) - `.characters` was already array
|
|
48
|
+
- Replace `.team` calls with `.teams_raw_data` (for string) - `.teams` was already array
|
|
49
|
+
- Replace `.location` calls with `.locations_raw_data` (for string) - `.locations` was already array
|
|
50
|
+
- Replace `.story_arc` calls with `.story_arcs` (now returns array) or `.story_arcs_raw_data` (for string)
|
|
51
|
+
- Replace `.story_arc_number` calls with `.story_arc_numbers` (now returns array) or `.story_arc_numbers_raw_data` (for string)
|
|
52
|
+
|
|
53
|
+
### Export Hash Changes
|
|
54
|
+
- Hash exports now include both `:genre` and `:genres_raw_data` keys with identical raw string values
|
|
55
|
+
- Hash exports now include both `:story_arc` and `:story_arcs_raw_data` keys with identical raw string values
|
|
56
|
+
- Hash exports now include both `:story_arc_number` and `:story_arc_numbers_raw_data` keys with identical raw string values
|
|
57
|
+
- This maintains backward compatibility while supporting the new API design
|
|
58
|
+
|
|
8
59
|
## [1.0.0] - 2025-10-05
|
|
9
60
|
|
|
10
61
|
### Added
|
|
@@ -33,7 +84,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
33
84
|
- **Pages**: Complete page object model with type predicates and attributes
|
|
34
85
|
- **Multi-value**: Smart handling of comma/space-separated field values
|
|
35
86
|
|
|
36
|
-
## [0.1.0] - 2025-
|
|
87
|
+
## [0.1.0] - 2025-10-05
|
|
37
88
|
|
|
38
89
|
### Added
|
|
39
90
|
- Initial project structure
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A Ruby gem that provides an idiomatic interface for reading and writing ComicInf
|
|
|
4
4
|
following the official ComicInfo schema specifications from the
|
|
5
5
|
[Anansi Project](https://github.com/anansi-project/comicinfo).
|
|
6
6
|
|
|
7
|
-

|
|
8
8
|

|
|
9
9
|

|
|
10
10
|
|
|
@@ -17,7 +17,8 @@ following the official ComicInfo schema specifications from the
|
|
|
17
17
|
- 📖 **Manga Support**: Right-to-left reading direction and manga-specific fields
|
|
18
18
|
- ✅ **Comprehensive Validation**: Schema-compliant enum validation and type coercion
|
|
19
19
|
- 🚨 **Detailed Error Handling**: Custom exception classes with helpful error messages
|
|
20
|
-
- 📊 **Export Support**: JSON and
|
|
20
|
+
- 📊 **Export Support**: JSON, YAML, and XML serialization with hash representation
|
|
21
|
+
- ✍️ **XML Generation**: Complete ComicInfo.xml writing with round-trip consistency
|
|
21
22
|
|
|
22
23
|
## Installation
|
|
23
24
|
|
|
@@ -77,7 +78,7 @@ puts comic.cover_artist #=> "Ryan Ottley"
|
|
|
77
78
|
|
|
78
79
|
# Content details
|
|
79
80
|
puts comic.page_count #=> 20
|
|
80
|
-
puts comic.
|
|
81
|
+
puts comic.genres #=> ["Superhero", "Action", "Adventure"]
|
|
81
82
|
puts comic.language_iso #=> "en-US"
|
|
82
83
|
puts comic.format #=> "Digital"
|
|
83
84
|
|
|
@@ -108,8 +109,38 @@ teams = comic.teams #=> ["Avengers"]
|
|
|
108
109
|
locations = comic.locations #=> ["New York City", "Manhattan", ...]
|
|
109
110
|
genres = comic.genres #=> ["Superhero", "Action", "Adventure"]
|
|
110
111
|
web_urls = comic.web_urls #=> ["https://marvel.com/...", "https://comicvine.com/..."]
|
|
112
|
+
|
|
113
|
+
# Raw data methods for original comma-separated strings
|
|
114
|
+
genres_raw = comic.genres_raw_data #=> "Superhero, Action, Adventure"
|
|
115
|
+
characters_raw = comic.characters_raw_data #=> "Spider-Man, Peter Parker, J. Jonah Jameson, Aunt May"
|
|
116
|
+
story_arcs_raw = comic.story_arcs_raw_data #=> "Brand New Day, Spider-Island"
|
|
117
|
+
|
|
118
|
+
# Singular schema elements alias to plural arrays
|
|
119
|
+
genre = comic.genre #=> ["Superhero", "Action", "Adventure"] (same as genres)
|
|
120
|
+
story_arc = comic.story_arc #=> ["Brand New Day", "Spider-Island"] (same as story_arcs)
|
|
121
|
+
story_arc_num = comic.story_arc_number #=> ["1", "5"] (same as story_arc_numbers)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### File Names from Templates
|
|
125
|
+
|
|
126
|
+
Name a comic's file, or its page image files, from its details. The result has no extension.
|
|
127
|
+
|
|
128
|
+
```ruby
|
|
129
|
+
comic.filename template: '{series} #{number} ({year})' #=> "Saga #1 (2012)"
|
|
130
|
+
comic.filename template: '{series} #{number:3}' #=> "Saga #001"
|
|
131
|
+
|
|
132
|
+
comic.page_filename template: 'page_{page:3}', page: 1, of: 22 #=> "page_001"
|
|
133
|
+
comic.page_filename template: '{series}_{number:3}_{page:4}', page: 12, of: 22 #=> "Saga_001_0012"
|
|
111
134
|
```
|
|
112
135
|
|
|
136
|
+
Write templates in single quotes: in double quotes Ruby reads `#{number}` as interpolation.
|
|
137
|
+
|
|
138
|
+
- **Tokens**: `{number}` `{publisher}` `{series}` `{title}` `{volume}` `{year}`, and `{page}` in a page template. They are listed in `ComicInfo::FilenameTemplate::TOKENS` and `PAGE_TOKENS`.
|
|
139
|
+
- **Padding**: `{number:3}` and `{page:3}` pad with zeros to that many digits. Only the whole number a value starts with is padded: `1.5` becomes `001.5` and `12AU` becomes `012AU`.
|
|
140
|
+
- **Missing values** are left out along with the decoration around them: `Saga # ()` becomes `Saga`.
|
|
141
|
+
- **`/` and `:`** in a value become `-`, since they cannot be part of a file name.
|
|
142
|
+
- **Page names always sort in page order**: the page number is at least as wide as the page count (page 2 of 10 is `02`), and a template without `{page}` gets the number appended.
|
|
143
|
+
|
|
113
144
|
### Working with Pages
|
|
114
145
|
|
|
115
146
|
```ruby
|
|
@@ -125,13 +156,36 @@ page = comic.pages.first
|
|
|
125
156
|
puts page.cover? #=> true for FrontCover, BackCover, InnerCover
|
|
126
157
|
puts page.story? #=> true for Story pages
|
|
127
158
|
puts page.deleted? #=> true for Deleted pages
|
|
159
|
+
|
|
160
|
+
# A page can carry more than one type (space-separated in the XML)
|
|
161
|
+
puts page.type #=> "FrontCover"
|
|
162
|
+
puts page.types #=> ["FrontCover"]
|
|
163
|
+
puts page.include_type? 'Story' #=> false
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Changing Pages
|
|
167
|
+
|
|
168
|
+
An issue is not changed in place. These return a changed copy, which you can `save` or turn `to_xml`.
|
|
169
|
+
|
|
170
|
+
```ruby
|
|
171
|
+
# A page's type, by its image index. A page with no <Page> entry is a Story page.
|
|
172
|
+
comic.page_type at: 0 #=> "FrontCover"
|
|
173
|
+
|
|
174
|
+
# Give a page a type. Its entry keeps everything else; a page with no entry gets one.
|
|
175
|
+
updated = comic.setting_page_type 'Advertisement', at: 4
|
|
176
|
+
|
|
177
|
+
# Bring the <Page> entries and PageCount up to date after the page images were reordered,
|
|
178
|
+
# deleted, or added to. Each item is the index that image had before, or nil for a new image.
|
|
179
|
+
# Here the third page moves to the front, the second is deleted, and a new page is added.
|
|
180
|
+
updated = comic.rearranging_pages [2, 0, nil]
|
|
181
|
+
updated.save 'ComicInfo.xml'
|
|
128
182
|
```
|
|
129
183
|
|
|
130
184
|
### Manga Support
|
|
131
185
|
|
|
132
186
|
```ruby
|
|
133
187
|
# Load a manga ComicInfo file
|
|
134
|
-
manga = ComicInfo.load 'path/to/manga/ComicInfo.xml'
|
|
188
|
+
manga = ComicInfo.load 'path/to/manga/ComicInfo.xml'
|
|
135
189
|
|
|
136
190
|
puts manga.title #=> "進撃の巨人"
|
|
137
191
|
puts manga.series #=> "Attack on Titan"
|
|
@@ -167,9 +221,17 @@ This gem fully supports the ComicInfo v2.0 XSD schema with all field types:
|
|
|
167
221
|
### String Fields
|
|
168
222
|
- Title, Series, Number, Summary, Notes
|
|
169
223
|
- Creator fields (Writer, Penciller, Inker, Colorist, Letterer, CoverArtist, Editor, Translator)
|
|
170
|
-
- Publication fields (Publisher, Imprint,
|
|
171
|
-
- Character/Location fields (
|
|
172
|
-
- Story fields (
|
|
224
|
+
- Publication fields (Publisher, Imprint, Web, LanguageISO, Format)
|
|
225
|
+
- Character/Location fields (MainCharacterOrTeam)
|
|
226
|
+
- Story fields (SeriesGroup, ScanInformation, Review)
|
|
227
|
+
|
|
228
|
+
### Multi-value Fields (String + Array Access)
|
|
229
|
+
- Genre/Genres: Raw comma-separated string + parsed array
|
|
230
|
+
- Characters: Raw comma-separated string + parsed array
|
|
231
|
+
- Teams: Raw comma-separated string + parsed array
|
|
232
|
+
- Locations: Raw comma-separated string + parsed array
|
|
233
|
+
- StoryArc/StoryArcs: Raw comma-separated string + parsed array
|
|
234
|
+
- StoryArcNumber/StoryArcNumbers: Raw comma-separated string + parsed array
|
|
173
235
|
|
|
174
236
|
### Integer Fields
|
|
175
237
|
- Count, Volume, AlternateCount, PageCount
|
|
@@ -181,7 +243,10 @@ This gem fully supports the ComicInfo v2.0 XSD schema with all field types:
|
|
|
181
243
|
- AgeRating: Various ESRB and international ratings
|
|
182
244
|
|
|
183
245
|
### Decimal Fields
|
|
184
|
-
- CommunityRating: 0.0 to 5.0 range with validation
|
|
246
|
+
- CommunityRating: 0.0 to 5.0 range with validation (a `Float`, `nil` when absent)
|
|
247
|
+
|
|
248
|
+
### Default Values
|
|
249
|
+
- Missing string fields are `""`, missing integer fields are `-1`, missing enum fields are `"Unknown"`
|
|
185
250
|
|
|
186
251
|
### Complex Fields
|
|
187
252
|
- Pages: Array of ComicPageInfo objects with full attribute support
|
|
@@ -190,9 +255,10 @@ This gem fully supports the ComicInfo v2.0 XSD schema with all field types:
|
|
|
190
255
|
### Export Formats
|
|
191
256
|
- **JSON**: Complete serialization with all fields
|
|
192
257
|
- **YAML**: Human-readable format with array structures
|
|
258
|
+
- **XML**: Valid ComicInfo v2.0 compliant XML generation
|
|
193
259
|
- **Hash**: Ruby hash representation with symbol keys
|
|
194
260
|
|
|
195
|
-
### Data Export
|
|
261
|
+
### Data Export & XML Generation
|
|
196
262
|
|
|
197
263
|
```ruby
|
|
198
264
|
comic = ComicInfo.load 'path/to/ComicInfo.xml'
|
|
@@ -205,11 +271,27 @@ puts JSON.pretty_generate(JSON.parse(json_string))
|
|
|
205
271
|
yaml_string = comic.to_yaml
|
|
206
272
|
puts yaml_string
|
|
207
273
|
|
|
274
|
+
# Generate XML
|
|
275
|
+
xml_string = comic.to_xml
|
|
276
|
+
puts xml_string
|
|
277
|
+
|
|
278
|
+
# Save to file
|
|
279
|
+
comic.save 'path/to/new/ComicInfo.xml'
|
|
280
|
+
|
|
281
|
+
# Save to IO object
|
|
282
|
+
File.open('path/to/new/ComicInfo.xml', 'w') do |file|
|
|
283
|
+
comic.save file
|
|
284
|
+
end
|
|
285
|
+
|
|
208
286
|
# Export as Hash
|
|
209
287
|
hash = comic.to_h
|
|
210
|
-
puts hash[:title]
|
|
211
|
-
puts hash[:
|
|
212
|
-
puts hash[:
|
|
288
|
+
puts hash[:title] #=> "The Amazing Spider-Man"
|
|
289
|
+
puts hash[:genre] #=> "Superhero, Action, Adventure" (raw data)
|
|
290
|
+
puts hash[:genres] #=> ["Superhero", "Action", "Adventure"] (parsed array)
|
|
291
|
+
puts hash[:genres_raw_data] #=> "Superhero, Action, Adventure" (same as :genre)
|
|
292
|
+
puts hash[:characters] #=> ["Spider-Man", "Peter Parker", ...]
|
|
293
|
+
puts hash[:characters_raw_data] #=> "Spider-Man, Peter Parker, J. Jonah Jameson, Aunt May"
|
|
294
|
+
puts hash[:pages].length #=> 12
|
|
213
295
|
```
|
|
214
296
|
|
|
215
297
|
## Development
|
|
@@ -252,18 +334,19 @@ bundle exec rubocop --autocorrect
|
|
|
252
334
|
|
|
253
335
|
### Current Features ✅
|
|
254
336
|
- **Core Reading**: Complete ComicInfo.xml parsing
|
|
337
|
+
- **XML Writing**: Full ComicInfo.xml generation with round-trip consistency
|
|
255
338
|
- **Schema Compliance**: Full ComicInfo v2.0 support
|
|
256
339
|
- **Field Types**: String, Integer, Decimal, Enum, Boolean, Arrays
|
|
257
340
|
- **Multi-value Fields**: Both string and array access methods
|
|
258
|
-
- **Issue &Page Support**: Complete Issue and nested Page objects
|
|
341
|
+
- **Issue & Page Support**: Complete Issue and nested Page objects
|
|
259
342
|
- **Error Handling**: Custom exceptions with detailed messages
|
|
260
|
-
- **Data Export**: JSON and
|
|
343
|
+
- **Data Export**: JSON, YAML, and XML serialization
|
|
261
344
|
- **Validation**: Enum values, ranges, type coercion
|
|
262
345
|
- **Unicode Support**: International characters and special symbols
|
|
263
|
-
- **
|
|
346
|
+
- **File Names**: Comic and page file names from templates
|
|
347
|
+
- **Page Changes**: Set a page's type, and keep page entries in step with reordered, deleted, and added pages
|
|
264
348
|
|
|
265
349
|
### Planned Features 🚧
|
|
266
|
-
- **XML Generation**: Writing ComicInfo.xml files
|
|
267
350
|
- **CLI Tool**: Command-line interface for file manipulation
|
|
268
351
|
- **Schema Migration**: Support for multiple ComicInfo versions
|
|
269
352
|
|
data/doc/development.md
CHANGED
|
@@ -13,13 +13,13 @@ following the official ComicInfo schema specifications from the Anansi Project.
|
|
|
13
13
|
## Code Standards
|
|
14
14
|
|
|
15
15
|
### Ruby Version
|
|
16
|
-
- Minimum required: Ruby
|
|
16
|
+
- Minimum required: Ruby 4.0.9+
|
|
17
17
|
- Use modern Ruby features and syntax patterns
|
|
18
18
|
|
|
19
19
|
### Dependencies
|
|
20
|
-
- **nokogiri** (>= 1.
|
|
21
|
-
- **rspec
|
|
22
|
-
- **rubocop** (
|
|
20
|
+
- **nokogiri** (>= 1.19.3): XML parsing and generation (the only runtime dependency)
|
|
21
|
+
- **rspec**: Testing framework
|
|
22
|
+
- **rubocop** (with `rubocop-performance`, `rubocop-rake`, `rubocop-rspec`): Code linting and formatting
|
|
23
23
|
|
|
24
24
|
### Code Style
|
|
25
25
|
- Follow RuboCop rules (configured in `.rubocop.yml`)
|
|
@@ -41,6 +41,7 @@ lib/
|
|
|
41
41
|
├─ comicinfo.rb # Main module and autoloads
|
|
42
42
|
├─ comicinfo/
|
|
43
43
|
│ ├─ version.rb # Gem version constant
|
|
44
|
+
│ ├─ filename_template.rb # File names from templates, for Issue#filename and #page_filename
|
|
44
45
|
│ ├─ issue.rb # Main ComicInfo::Issue class
|
|
45
46
|
│ ├─ page.rb # ComicInfo::Page class
|
|
46
47
|
│ ├─ enums.rb # Schema enum definitions
|
|
@@ -49,13 +50,21 @@ spec/
|
|
|
49
50
|
├─ spec_helper.rb # RSpec configuration with FixtureHelpers
|
|
50
51
|
├─ comic_info_spec.rb # Main module specs
|
|
51
52
|
├─ comic_info/
|
|
53
|
+
│ ├─ filename_template_spec.rb # File name template specs
|
|
54
|
+
│ ├─ issue_pages_spec.rb # Changing an issue's page entries
|
|
52
55
|
│ ├─ issue_spec.rb # ComicInfo::Issue class specs
|
|
53
56
|
│ └─ page_spec.rb # ComicInfo::Page class specs
|
|
54
57
|
└─ fixtures/ # XML test fixtures
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
├─ valid_minimal.xml
|
|
59
|
+
├─ valid_complete.xml
|
|
60
|
+
├─ invalid_xml.xml
|
|
61
|
+
├─ edge_cases/
|
|
62
|
+
└─ output/ # Scratch space for write specs
|
|
63
|
+
schemas/ # ComicInfo XSD files (1.0, 2.0, 2.1-draft)
|
|
64
|
+
script/
|
|
65
|
+
└─ schema # Downloads the XSD files into schemas/
|
|
66
|
+
sig/
|
|
67
|
+
└─ comicinfo.rbs # RBS signatures
|
|
59
68
|
```
|
|
60
69
|
|
|
61
70
|
## API Design Principles
|
|
@@ -73,13 +82,13 @@ comic.count #=> Integer
|
|
|
73
82
|
comic.pages #=> Array<ComicInfo::Page>
|
|
74
83
|
comic.black_and_white #=> String (enum value)
|
|
75
84
|
|
|
76
|
-
# Multi-value fields have
|
|
77
|
-
comic.
|
|
78
|
-
comic.
|
|
79
|
-
comic.
|
|
80
|
-
comic.
|
|
81
|
-
comic.
|
|
82
|
-
comic.
|
|
85
|
+
# Multi-value fields have a plural method and a raw data method
|
|
86
|
+
comic.characters #=> Array<String>
|
|
87
|
+
comic.characters_raw_data #=> String (comma-separated)
|
|
88
|
+
comic.genres #=> Array<String>
|
|
89
|
+
comic.genres_raw_data #=> String (comma-separated)
|
|
90
|
+
comic.web_urls #=> Array<String>
|
|
91
|
+
comic.web #=> String (space-separated URLs)
|
|
83
92
|
```
|
|
84
93
|
|
|
85
94
|
### Naming Conventions
|
|
@@ -90,10 +99,12 @@ comic.web_urls #=> Array<String>
|
|
|
90
99
|
- XML `<BlackAndWhite>` → Ruby `#black_and_white`
|
|
91
100
|
- XML `<CommunityRating>` → Ruby `#community_rating`
|
|
92
101
|
- Multi-value fields:
|
|
93
|
-
- Singular method returns original string from XML
|
|
94
102
|
- Plural method returns array of split values
|
|
95
|
-
-
|
|
96
|
-
- XML `<
|
|
103
|
+
- `_raw_data` method returns original string from XML
|
|
104
|
+
- XML `<Characters>` → Ruby `#characters` (array) & `#characters_raw_data` (string)
|
|
105
|
+
- XML `<Teams>` → Ruby `#teams` (array) & `#teams_raw_data` (string)
|
|
106
|
+
- Where the schema element is singular, the singular method is an alias of the plural:
|
|
107
|
+
`#genre`, `#story_arc`, `#story_arc_number` return arrays
|
|
97
108
|
|
|
98
109
|
### Error Handling
|
|
99
110
|
- Define custom exception classes in `ComicInfo::Errors`
|
|
@@ -138,13 +149,13 @@ bundle exec rspec --format documentation
|
|
|
138
149
|
|
|
139
150
|
### Multi-value Fields
|
|
140
151
|
- Handle comma-separated values in fields like Genre, Characters
|
|
141
|
-
- Provide both string and array access methods
|
|
152
|
+
- Provide both string (`_raw_data`) and array (plural) access methods
|
|
142
153
|
- Preserve original formatting when possible
|
|
143
154
|
|
|
144
155
|
### Type Coercion
|
|
145
156
|
- String fields: preserve as-is from XML
|
|
146
157
|
- Integer fields: convert with proper error handling
|
|
147
|
-
- Decimal fields:
|
|
158
|
+
- Decimal fields: convert to Float with proper error handling
|
|
148
159
|
- Boolean attributes: handle "true"/"false" strings
|
|
149
160
|
|
|
150
161
|
### Default Values
|
|
@@ -152,6 +163,7 @@ bundle exec rspec --format documentation
|
|
|
152
163
|
- Empty strings for string fields
|
|
153
164
|
- -1 for unset integer fields
|
|
154
165
|
- "Unknown" for enum fields where applicable
|
|
166
|
+
- `nil` for an unset CommunityRating
|
|
155
167
|
|
|
156
168
|
## Testing Strategy
|
|
157
169
|
|
|
@@ -197,9 +209,9 @@ RSpec.describe ComicInfo::Issue do
|
|
|
197
209
|
end
|
|
198
210
|
|
|
199
211
|
describe 'multi-value fields' do
|
|
200
|
-
describe '
|
|
201
|
-
it 'returns
|
|
202
|
-
expect(complete_comic.
|
|
212
|
+
describe 'raw data methods (return strings)' do
|
|
213
|
+
it 'returns characters as comma-separated string' do
|
|
214
|
+
expect(complete_comic.characters_raw_data).to eq 'Spider-Man, Peter Parker'
|
|
203
215
|
end
|
|
204
216
|
end
|
|
205
217
|
|
|
@@ -235,21 +247,19 @@ end
|
|
|
235
247
|
- Maintain comprehensive README with examples
|
|
236
248
|
- Document all public methods with YARD comments
|
|
237
249
|
- Include schema field descriptions in code comments
|
|
238
|
-
-
|
|
250
|
+
- Only schema 2.0 is implemented; the 1.0 and 2.1-draft XSD files are kept in `schemas/` for reference
|
|
239
251
|
|
|
240
252
|
## Implementation Status
|
|
241
253
|
- ✅ Core reading functionality complete
|
|
254
|
+
- ✅ XML writing (`#to_xml`, `#save`)
|
|
255
|
+
- ✅ JSON, YAML and Hash export (`#to_json`, `#to_yaml`, `#to_h`)
|
|
242
256
|
- ✅ All schema fields implemented and tested
|
|
243
|
-
- ✅ Comprehensive test suite (156 test cases)
|
|
244
257
|
- ✅ Error handling with custom exception classes
|
|
245
|
-
- ✅ Multi-value field support (
|
|
258
|
+
- ✅ Multi-value field support (plural and `_raw_data` methods)
|
|
246
259
|
- ✅ Page objects with full attribute support
|
|
247
260
|
- ✅ Enum validation and type coercion
|
|
248
261
|
- ✅ Unicode and special character handling
|
|
249
262
|
|
|
250
263
|
## Future Considerations
|
|
251
|
-
- XML writing/generation capabilities (.to_xml method)
|
|
252
|
-
- JSON export (.to_json method) - **Partially implemented**
|
|
253
|
-
- YAML export (.to_yaml method) - **Partially implemented**
|
|
254
264
|
- Schema version detection and migration
|
|
255
265
|
- CLI tool for ComicInfo manipulation
|
data/lib/comicinfo/enums.rb
CHANGED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
require_relative 'enums'
|
|
2
|
+
|
|
3
|
+
module ComicInfo
|
|
4
|
+
# Fills in a file name template, such as "{series} #{number} ({year})", from an issue.
|
|
5
|
+
#
|
|
6
|
+
# A value the issue lacks is left out, along with decoration that would be left empty around it:
|
|
7
|
+
# "Saga # ()" becomes "Saga". "/" and ":" in a value become "-", since they cannot be part of a
|
|
8
|
+
# file name. Anything else in the template, including a {name} that is not a token, is kept as
|
|
9
|
+
# written. The result has no file extension.
|
|
10
|
+
class FilenameTemplate
|
|
11
|
+
# The names #filename fills in, written in a template as {name}.
|
|
12
|
+
TOKENS = %w[number publisher series title volume year].freeze
|
|
13
|
+
|
|
14
|
+
# The names #page_filename fills in: TOKENS and page.
|
|
15
|
+
PAGE_TOKENS = [*TOKENS, 'page'].freeze
|
|
16
|
+
|
|
17
|
+
EMPTY_DECORATION = ['()', '[]'].freeze
|
|
18
|
+
|
|
19
|
+
def initialize template
|
|
20
|
+
@template = template.to_s
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# A file name for the issue.
|
|
24
|
+
#
|
|
25
|
+
# Write {number:3} to pad the issue number with zeros to that many digits (1 to 99). Only the
|
|
26
|
+
# whole number it starts with is padded: "1.5" becomes "001.5" and "12AU" becomes "012AU".
|
|
27
|
+
def filename issue
|
|
28
|
+
fill template, issue
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# A file name for one of the issue's page images.
|
|
32
|
+
#
|
|
33
|
+
# {page} is the page number, and {page:3} pads it with zeros to that many digits (1 to 99).
|
|
34
|
+
# Page files are read in name order, so the result always keeps pages apart and in order:
|
|
35
|
+
# the page number is at least as wide as the page count, a template with no page number gets
|
|
36
|
+
# one appended after "_", and a name that would be empty is the page number alone.
|
|
37
|
+
# "/" and ":" anywhere in the result become "-".
|
|
38
|
+
def page_filename issue, page:, of:
|
|
39
|
+
minimum_width = [page, of].max.to_s.length
|
|
40
|
+
number = zero_padded page.to_s, minimum_width
|
|
41
|
+
numbered = fill_padded('page', number, template).gsub('{page}', number)
|
|
42
|
+
name = fill numbered, issue
|
|
43
|
+
|
|
44
|
+
complete = if numbered != template then name
|
|
45
|
+
elsif name.empty? then number
|
|
46
|
+
else
|
|
47
|
+
"#{name}_#{number}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
complete.tr '/:', '-'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
attr_reader :template
|
|
56
|
+
|
|
57
|
+
def fill text, issue
|
|
58
|
+
name = fill_padded 'number', value(issue, 'number'), text
|
|
59
|
+
TOKENS.each { name = name.gsub("{#{it}}", value(issue, it)) }
|
|
60
|
+
tidy name
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Fills in each {token:width} with the value padded to that width, leaving one whose width is
|
|
64
|
+
# not 1 to 99 as written.
|
|
65
|
+
def fill_padded token, value, text
|
|
66
|
+
text.gsub(/\{#{token}:(\d{1,2})\}/) do |written|
|
|
67
|
+
width = Regexp.last_match(1).to_i
|
|
68
|
+
width.zero? ? written : zero_padded(value, width)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Pads the whole number the value starts with: "1.5" to "001.5" for a width of 3.
|
|
73
|
+
def zero_padded value, width
|
|
74
|
+
whole = value[/\A\d+/]
|
|
75
|
+
return value if whole.nil? || whole.length >= width
|
|
76
|
+
|
|
77
|
+
('0' * (width - whole.length)) + value
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def value issue, token
|
|
81
|
+
raw = case token
|
|
82
|
+
when 'number' then issue.number
|
|
83
|
+
when 'publisher' then issue.publisher
|
|
84
|
+
when 'series' then issue.series
|
|
85
|
+
when 'title' then issue.title
|
|
86
|
+
when 'volume' then integer issue.volume
|
|
87
|
+
when 'year' then integer issue.year
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
raw.to_s.tr('/:', '-').strip
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def integer value
|
|
94
|
+
value == Enums::DEFAULT_INTEGER ? nil : value
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Removes decoration left empty by missing values, then collapses whitespace.
|
|
98
|
+
def tidy name
|
|
99
|
+
tidied = EMPTY_DECORATION.reduce(name) { |text, empty| text.gsub empty, '' }
|
|
100
|
+
tidied.split.reject { it == '#' }.join ' '
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
data/lib/comicinfo/issue.rb
CHANGED
|
@@ -2,8 +2,10 @@ require 'nokogiri'
|
|
|
2
2
|
require 'date'
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'yaml'
|
|
5
|
+
require 'fileutils'
|
|
5
6
|
require_relative 'enums'
|
|
6
7
|
require_relative 'errors'
|
|
8
|
+
require_relative 'filename_template'
|
|
7
9
|
require_relative 'page'
|
|
8
10
|
|
|
9
11
|
module ComicInfo
|
|
@@ -11,12 +13,10 @@ module ComicInfo
|
|
|
11
13
|
# Follows the ComicInfo XSD schema v2.0 specification
|
|
12
14
|
class Issue
|
|
13
15
|
# String fields from ComicInfo schema
|
|
14
|
-
attr_reader :
|
|
15
|
-
:
|
|
16
|
-
:
|
|
17
|
-
:
|
|
18
|
-
:team, :location, :scan_information, :story_arc, :story_arc_number,
|
|
19
|
-
:series_group, :main_character_or_team, :review
|
|
16
|
+
attr_reader :alternate_number, :alternate_series, :colorist, :cover_artist, :editor,
|
|
17
|
+
:format, :imprint, :inker, :language_iso, :letterer, :main_character_or_team,
|
|
18
|
+
:notes, :number, :penciller, :publisher, :review, :scan_information, :series,
|
|
19
|
+
:series_group, :summary, :title, :translator, :web, :writer
|
|
20
20
|
|
|
21
21
|
# Integer fields from ComicInfo schema
|
|
22
22
|
attr_reader :count, :volume, :alternate_count, :year, :month, :day, :page_count
|
|
@@ -121,6 +121,76 @@ module ComicInfo
|
|
|
121
121
|
@pages.select(&:story?)
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
+
# A file name for this issue, without an extension, made by filling in a template such as
|
|
125
|
+
# "{series} #{number} ({year})". See FilenameTemplate for the tokens and rules.
|
|
126
|
+
def filename template:
|
|
127
|
+
FilenameTemplate.new(template).filename self
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# A file name for one of this issue's page images, without an extension, made by filling in a
|
|
131
|
+
# template such as "page_{page:3}". See FilenameTemplate for the tokens and rules.
|
|
132
|
+
def page_filename template:, page:, of:
|
|
133
|
+
FilenameTemplate.new(template).page_filename self, page:, of:
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# The same issue after its page images were reordered, deleted, or added to.
|
|
137
|
+
#
|
|
138
|
+
# A <Page> entry points at its image by index, so when the images change the entries must
|
|
139
|
+
# follow. `order` describes the new images: order[i] is the index the image now at position i
|
|
140
|
+
# had before, or nil for an image that is new.
|
|
141
|
+
#
|
|
142
|
+
# # Three pages; the last is moved to the front and a new page is appended.
|
|
143
|
+
# updated = issue.rearranging_pages [2, 0, 1, nil]
|
|
144
|
+
#
|
|
145
|
+
# - A page keeps its entry (type, bookmark, sizes) under its new index.
|
|
146
|
+
# - A deleted page loses its entry.
|
|
147
|
+
# - A page that had no entry still has none.
|
|
148
|
+
# - A new page gets a default entry, but only if the issue has page entries at all.
|
|
149
|
+
# - page_count becomes the new number of pages, but only if it was set.
|
|
150
|
+
#
|
|
151
|
+
# Returns a copy; this issue is not changed.
|
|
152
|
+
def rearranging_pages order
|
|
153
|
+
rearranged = rearranged_pages order
|
|
154
|
+
count = @page_count == Enums::DEFAULT_PAGE_COUNT ? @page_count : order.length
|
|
155
|
+
|
|
156
|
+
with_pages rearranged, page_count: count
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# The type of the page image at an index (0-based, as in Page#image).
|
|
160
|
+
#
|
|
161
|
+
# This is the first type of that image's <Page> entry. A page with no entry is a Story page,
|
|
162
|
+
# as the schema says.
|
|
163
|
+
def page_type at:
|
|
164
|
+
entry = @pages.find { it.image == at }
|
|
165
|
+
entry ? entry.types.first : Enums::DEFAULT_PAGE_TYPE
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# The same issue with the page image at an index given a type.
|
|
169
|
+
#
|
|
170
|
+
# updated = issue.setting_page_type 'FrontCover', at: 0
|
|
171
|
+
#
|
|
172
|
+
# - The page's entry keeps everything else it has (bookmark, sizes); the type replaces all of
|
|
173
|
+
# the types it had.
|
|
174
|
+
# - A page with no entry gets one, placed in image order.
|
|
175
|
+
# - Setting Story on a page with no entry changes nothing, since that is already its type.
|
|
176
|
+
#
|
|
177
|
+
# Returns a copy; this issue is not changed. Raises Errors::InvalidEnumError for a type the
|
|
178
|
+
# schema does not have.
|
|
179
|
+
def setting_page_type type, at:
|
|
180
|
+
Enums::Validators.validate_comic_page_type type
|
|
181
|
+
position = @pages.index { it.image == at }
|
|
182
|
+
|
|
183
|
+
if position
|
|
184
|
+
updated = @pages.dup
|
|
185
|
+
updated[position] = @pages[position].with_type type
|
|
186
|
+
return with_pages updated, page_count: @page_count
|
|
187
|
+
end
|
|
188
|
+
return self if type == Enums::DEFAULT_PAGE_TYPE
|
|
189
|
+
|
|
190
|
+
added = [*@pages, Page.new(image: at, type:)]
|
|
191
|
+
with_pages added.sort_by(&:image), page_count: @page_count
|
|
192
|
+
end
|
|
193
|
+
|
|
124
194
|
# Get publication date as Date object if available
|
|
125
195
|
def publication_date
|
|
126
196
|
return nil if @year == Enums::DEFAULT_INTEGER
|
|
@@ -137,34 +207,115 @@ module ComicInfo
|
|
|
137
207
|
end
|
|
138
208
|
|
|
139
209
|
# Plural methods that return arrays
|
|
140
|
-
def genres
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
def
|
|
145
|
-
|
|
146
|
-
end
|
|
210
|
+
def genres = split_comma_separated @genre
|
|
211
|
+
def characters = split_comma_separated @character
|
|
212
|
+
def teams = split_comma_separated @team
|
|
213
|
+
def locations = split_comma_separated @location
|
|
214
|
+
def story_arcs = split_comma_separated @story_arc
|
|
215
|
+
def story_arc_numbers = split_comma_separated @story_arc_number
|
|
147
216
|
|
|
148
|
-
def
|
|
149
|
-
|
|
150
|
-
end
|
|
217
|
+
def web_urls
|
|
218
|
+
return [] if @web.empty?
|
|
151
219
|
|
|
152
|
-
|
|
153
|
-
split_comma_separated(@location)
|
|
220
|
+
@web.split(/\s+/)
|
|
154
221
|
end
|
|
155
222
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
223
|
+
# Raw data methods that return the original string values
|
|
224
|
+
def genres_raw_data = @genre
|
|
225
|
+
def characters_raw_data = @character
|
|
226
|
+
def teams_raw_data = @team
|
|
227
|
+
def locations_raw_data = @location
|
|
228
|
+
def story_arcs_raw_data = @story_arc
|
|
229
|
+
def story_arc_numbers_raw_data = @story_arc_number
|
|
230
|
+
|
|
231
|
+
# Singular aliases for schema elements that are singular
|
|
232
|
+
alias genre genres
|
|
233
|
+
alias story_arc story_arcs
|
|
234
|
+
alias story_arc_number story_arc_numbers
|
|
235
|
+
|
|
236
|
+
# Convert to XML representation
|
|
237
|
+
def to_xml
|
|
238
|
+
doc = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
|
|
239
|
+
xml.ComicInfo('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
|
240
|
+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema') do
|
|
241
|
+
# String fields in schema order
|
|
242
|
+
xml.Title(@title) unless @title == Enums::DEFAULT_STRING
|
|
243
|
+
xml.Series(@series) unless @series == Enums::DEFAULT_STRING
|
|
244
|
+
xml.Number(@number) unless @number == Enums::DEFAULT_STRING
|
|
245
|
+
xml.Count(@count) unless @count == Enums::DEFAULT_INTEGER
|
|
246
|
+
xml.Volume(@volume) unless @volume == Enums::DEFAULT_INTEGER
|
|
247
|
+
xml.AlternateSeries(@alternate_series) unless @alternate_series == Enums::DEFAULT_STRING
|
|
248
|
+
xml.AlternateNumber(@alternate_number) unless @alternate_number == Enums::DEFAULT_STRING
|
|
249
|
+
xml.AlternateCount(@alternate_count) unless @alternate_count == Enums::DEFAULT_INTEGER
|
|
250
|
+
xml.Summary(@summary) unless @summary == Enums::DEFAULT_STRING
|
|
251
|
+
xml.Notes(@notes) unless @notes == Enums::DEFAULT_STRING
|
|
252
|
+
xml.Year(@year) unless @year == Enums::DEFAULT_INTEGER
|
|
253
|
+
xml.Month(@month) unless @month == Enums::DEFAULT_INTEGER
|
|
254
|
+
xml.Day(@day) unless @day == Enums::DEFAULT_INTEGER
|
|
255
|
+
xml.Writer(@writer) unless @writer == Enums::DEFAULT_STRING
|
|
256
|
+
xml.Penciller(@penciller) unless @penciller == Enums::DEFAULT_STRING
|
|
257
|
+
xml.Inker(@inker) unless @inker == Enums::DEFAULT_STRING
|
|
258
|
+
xml.Colorist(@colorist) unless @colorist == Enums::DEFAULT_STRING
|
|
259
|
+
xml.Letterer(@letterer) unless @letterer == Enums::DEFAULT_STRING
|
|
260
|
+
xml.CoverArtist(@cover_artist) unless @cover_artist == Enums::DEFAULT_STRING
|
|
261
|
+
xml.Editor(@editor) unless @editor == Enums::DEFAULT_STRING
|
|
262
|
+
xml.Translator(@translator) unless @translator == Enums::DEFAULT_STRING
|
|
263
|
+
xml.Publisher(@publisher) unless @publisher == Enums::DEFAULT_STRING
|
|
264
|
+
xml.Imprint(@imprint) unless @imprint == Enums::DEFAULT_STRING
|
|
265
|
+
xml.Genre(@genre) unless @genre == Enums::DEFAULT_STRING
|
|
266
|
+
xml.Web(@web) unless @web == Enums::DEFAULT_STRING
|
|
267
|
+
xml.PageCount(@page_count) unless @page_count == Enums::DEFAULT_PAGE_COUNT
|
|
268
|
+
xml.LanguageISO(@language_iso) unless @language_iso == Enums::DEFAULT_STRING
|
|
269
|
+
xml.Format(@format) unless @format == Enums::DEFAULT_STRING
|
|
270
|
+
xml.BlackAndWhite(@black_and_white) unless @black_and_white == Enums::DEFAULT_ENUM_UNKNOWN
|
|
271
|
+
xml.Manga(@manga) unless @manga == Enums::DEFAULT_ENUM_UNKNOWN
|
|
272
|
+
xml.Characters(@character) unless @character == Enums::DEFAULT_STRING
|
|
273
|
+
xml.Teams(@team) unless @team == Enums::DEFAULT_STRING
|
|
274
|
+
xml.Locations(@location) unless @location == Enums::DEFAULT_STRING
|
|
275
|
+
xml.ScanInformation(@scan_information) unless @scan_information == Enums::DEFAULT_STRING
|
|
276
|
+
xml.StoryArc(@story_arc) unless @story_arc == Enums::DEFAULT_STRING
|
|
277
|
+
xml.StoryArcNumber(@story_arc_number) unless @story_arc_number == Enums::DEFAULT_STRING
|
|
278
|
+
xml.SeriesGroup(@series_group) unless @series_group == Enums::DEFAULT_STRING
|
|
279
|
+
xml.AgeRating(@age_rating) unless @age_rating == Enums::DEFAULT_ENUM_UNKNOWN
|
|
280
|
+
xml.MainCharacterOrTeam(@main_character_or_team) unless @main_character_or_team == Enums::DEFAULT_STRING
|
|
281
|
+
xml.CommunityRating(@community_rating) unless @community_rating.nil?
|
|
282
|
+
xml.Review(@review) unless @review == Enums::DEFAULT_STRING
|
|
283
|
+
|
|
284
|
+
# Pages section
|
|
285
|
+
if @pages && !@pages.empty?
|
|
286
|
+
xml.Pages do
|
|
287
|
+
@pages.each do |page|
|
|
288
|
+
xml.Page(page.to_xml_attributes)
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
end
|
|
159
294
|
|
|
160
|
-
|
|
161
|
-
split_comma_separated(@story_arc_number)
|
|
295
|
+
doc.to_xml
|
|
162
296
|
end
|
|
163
297
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
298
|
+
# Save to file or IO object
|
|
299
|
+
def save file_path_or_io
|
|
300
|
+
xml_content = to_xml
|
|
301
|
+
|
|
302
|
+
case file_path_or_io
|
|
303
|
+
when String
|
|
304
|
+
begin
|
|
305
|
+
FileUtils.mkdir_p(File.dirname(file_path_or_io))
|
|
306
|
+
File.write(file_path_or_io, xml_content)
|
|
307
|
+
rescue StandardError => e
|
|
308
|
+
raise Errors::FileError, "Failed to write file '#{file_path_or_io}': #{e.message}"
|
|
309
|
+
end
|
|
310
|
+
when IO
|
|
311
|
+
begin
|
|
312
|
+
file_path_or_io.write(xml_content)
|
|
313
|
+
rescue StandardError => e
|
|
314
|
+
raise Errors::FileError, "Failed to write to IO object: #{e.message}"
|
|
315
|
+
end
|
|
316
|
+
else
|
|
317
|
+
raise Errors::FileError, 'Invalid file path or IO object'
|
|
318
|
+
end
|
|
168
319
|
end
|
|
169
320
|
|
|
170
321
|
# Convert to JSON representation
|
|
@@ -180,60 +331,85 @@ module ComicInfo
|
|
|
180
331
|
# Convert to hash representation for JSON serialization
|
|
181
332
|
def to_h
|
|
182
333
|
{
|
|
183
|
-
title:
|
|
184
|
-
series:
|
|
185
|
-
number:
|
|
186
|
-
count:
|
|
187
|
-
volume:
|
|
188
|
-
alternate_series:
|
|
189
|
-
alternate_number:
|
|
190
|
-
alternate_count:
|
|
191
|
-
summary:
|
|
192
|
-
notes:
|
|
193
|
-
year:
|
|
194
|
-
month:
|
|
195
|
-
day:
|
|
196
|
-
writer:
|
|
197
|
-
penciller:
|
|
198
|
-
inker:
|
|
199
|
-
colorist:
|
|
200
|
-
letterer:
|
|
201
|
-
cover_artist:
|
|
202
|
-
editor:
|
|
203
|
-
translator:
|
|
204
|
-
publisher:
|
|
205
|
-
imprint:
|
|
206
|
-
genre:
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
334
|
+
title: @title,
|
|
335
|
+
series: @series,
|
|
336
|
+
number: @number,
|
|
337
|
+
count: @count,
|
|
338
|
+
volume: @volume,
|
|
339
|
+
alternate_series: @alternate_series,
|
|
340
|
+
alternate_number: @alternate_number,
|
|
341
|
+
alternate_count: @alternate_count,
|
|
342
|
+
summary: @summary,
|
|
343
|
+
notes: @notes,
|
|
344
|
+
year: @year,
|
|
345
|
+
month: @month,
|
|
346
|
+
day: @day,
|
|
347
|
+
writer: @writer,
|
|
348
|
+
penciller: @penciller,
|
|
349
|
+
inker: @inker,
|
|
350
|
+
colorist: @colorist,
|
|
351
|
+
letterer: @letterer,
|
|
352
|
+
cover_artist: @cover_artist,
|
|
353
|
+
editor: @editor,
|
|
354
|
+
translator: @translator,
|
|
355
|
+
publisher: @publisher,
|
|
356
|
+
imprint: @imprint,
|
|
357
|
+
genre: @genre,
|
|
358
|
+
genres_raw_data: genres_raw_data,
|
|
359
|
+
genres: genres,
|
|
360
|
+
web: @web,
|
|
361
|
+
web_urls: web_urls,
|
|
362
|
+
page_count: @page_count,
|
|
363
|
+
language_iso: @language_iso,
|
|
364
|
+
format: @format,
|
|
365
|
+
black_and_white: @black_and_white,
|
|
366
|
+
manga: @manga,
|
|
367
|
+
characters_raw_data: characters_raw_data,
|
|
368
|
+
characters: characters,
|
|
369
|
+
teams_raw_data: teams_raw_data,
|
|
370
|
+
teams: teams,
|
|
371
|
+
locations_raw_data: locations_raw_data,
|
|
372
|
+
locations: locations,
|
|
373
|
+
scan_information: @scan_information,
|
|
374
|
+
story_arc: @story_arc,
|
|
375
|
+
story_arcs_raw_data: story_arcs_raw_data,
|
|
376
|
+
story_arcs: story_arcs,
|
|
377
|
+
story_arc_number: @story_arc_number,
|
|
378
|
+
story_arc_numbers_raw_data: story_arc_numbers_raw_data,
|
|
379
|
+
story_arc_numbers: story_arc_numbers,
|
|
380
|
+
series_group: @series_group,
|
|
381
|
+
age_rating: @age_rating,
|
|
382
|
+
main_character_or_team: @main_character_or_team,
|
|
383
|
+
community_rating: @community_rating,
|
|
384
|
+
review: @review,
|
|
385
|
+
pages: @pages.map(&:to_h)
|
|
232
386
|
}.compact
|
|
233
387
|
end
|
|
234
388
|
|
|
389
|
+
protected
|
|
390
|
+
|
|
391
|
+
attr_writer :pages, :page_count
|
|
392
|
+
|
|
235
393
|
private
|
|
236
394
|
|
|
395
|
+
# The same issue with different page entries and page count
|
|
396
|
+
def with_pages pages, page_count:
|
|
397
|
+
copy = dup
|
|
398
|
+
copy.pages = pages
|
|
399
|
+
copy.page_count = page_count
|
|
400
|
+
copy
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
def rearranged_pages order
|
|
404
|
+
return [] if @pages.empty?
|
|
405
|
+
|
|
406
|
+
order.each_with_index.filter_map do |previous_index, new_index|
|
|
407
|
+
next Page.new(image: new_index) if previous_index.nil?
|
|
408
|
+
|
|
409
|
+
@pages.find { it.image == previous_index }&.with_image new_index
|
|
410
|
+
end
|
|
411
|
+
end
|
|
412
|
+
|
|
237
413
|
def parse_fields
|
|
238
414
|
# String fields
|
|
239
415
|
@title = get_string_field('Title')
|
data/lib/comicinfo/page.rb
CHANGED
|
@@ -49,6 +49,16 @@ module ComicInfo
|
|
|
49
49
|
types.include?(type)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
# The same page entry pointing at a different image index
|
|
53
|
+
def with_image image
|
|
54
|
+
Page.new to_h.merge(image:)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# The same page entry with a different type, which replaces every type it had
|
|
58
|
+
def with_type type
|
|
59
|
+
Page.new to_h.merge(type:)
|
|
60
|
+
end
|
|
61
|
+
|
|
52
62
|
# Get image dimensions as a hash
|
|
53
63
|
def dimensions
|
|
54
64
|
{
|
data/lib/comicinfo/version.rb
CHANGED
data/lib/comicinfo.rb
CHANGED
|
@@ -7,6 +7,7 @@ module ComicInfo
|
|
|
7
7
|
autoload :Page, 'comicinfo/page'
|
|
8
8
|
autoload :Enums, 'comicinfo/enums'
|
|
9
9
|
autoload :Errors, 'comicinfo/errors'
|
|
10
|
+
autoload :FilenameTemplate, 'comicinfo/filename_template'
|
|
10
11
|
|
|
11
12
|
# Convenience method for loading ComicInfo files
|
|
12
13
|
def self.load file_path_or_xml_string
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: comicinfo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shane Becker
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 1.
|
|
18
|
+
version: 1.19.3
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 1.
|
|
25
|
+
version: 1.19.3
|
|
26
26
|
description: |
|
|
27
27
|
An idiomatic Ruby interface for reading and writing ComicInfo.xml files,
|
|
28
28
|
following the official ComicInfo schema specifications from the Anansi Project
|
|
@@ -42,6 +42,7 @@ files:
|
|
|
42
42
|
- lib/comicinfo.rb
|
|
43
43
|
- lib/comicinfo/enums.rb
|
|
44
44
|
- lib/comicinfo/errors.rb
|
|
45
|
+
- lib/comicinfo/filename_template.rb
|
|
45
46
|
- lib/comicinfo/issue.rb
|
|
46
47
|
- lib/comicinfo/page.rb
|
|
47
48
|
- lib/comicinfo/version.rb
|
|
@@ -66,14 +67,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
66
67
|
requirements:
|
|
67
68
|
- - ">="
|
|
68
69
|
- !ruby/object:Gem::Version
|
|
69
|
-
version:
|
|
70
|
+
version: 4.0.9
|
|
70
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
72
|
requirements:
|
|
72
73
|
- - ">="
|
|
73
74
|
- !ruby/object:Gem::Version
|
|
74
75
|
version: '0'
|
|
75
76
|
requirements: []
|
|
76
|
-
rubygems_version:
|
|
77
|
+
rubygems_version: 4.0.20
|
|
77
78
|
specification_version: 4
|
|
78
79
|
summary: Ruby interface for working with ComicInfo.xml files
|
|
79
80
|
test_files: []
|