Class: ComicInfo::Page
- Inherits:
-
Object
- Object
- ComicInfo::Page
- Defined in:
- lib/comicinfo/page.rb
Overview
Represents a single page in a comic book with metadata Maps to ComicPageInfo type in the ComicInfo XSD schema
Instance Attribute Summary collapse
-
#bookmark ⇒ Object
readonly
Page attributes from XSD schema.
-
#double_page ⇒ Object
readonly
Page attributes from XSD schema.
-
#image ⇒ Object
readonly
Page attributes from XSD schema.
-
#image_height ⇒ Object
readonly
Page attributes from XSD schema.
-
#image_size ⇒ Object
readonly
Page attributes from XSD schema.
-
#image_width ⇒ Object
readonly
Page attributes from XSD schema.
-
#key ⇒ Object
readonly
Page attributes from XSD schema.
-
#type ⇒ Object
readonly
Page attributes from XSD schema.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Equality comparison.
-
#aspect_ratio ⇒ Object
Get aspect ratio if dimensions are available.
-
#bookmarked? ⇒ Boolean
Check if this page has a bookmark.
-
#cover? ⇒ Boolean
Check if this page is a cover page.
-
#deleted? ⇒ Boolean
Check if this page should be deleted/hidden.
-
#dimensions ⇒ Object
Get image dimensions as a hash.
-
#dimensions_available? ⇒ Boolean
Check if image dimensions are available.
-
#double_page? ⇒ Boolean
Check if this is a double-page spread.
- #hash ⇒ Object
-
#include_type?(type) ⇒ Boolean
Check if page has a specific type.
-
#initialize(attributes = {}) ⇒ Page
constructor
A new instance of Page.
-
#inspect ⇒ Object
Detailed inspection.
-
#story? ⇒ Boolean
Check if this page is a story page.
-
#to_h ⇒ Object
Convert to hash representation.
-
#to_s ⇒ Object
String representation.
-
#to_xml_attributes ⇒ Object
Convert to XML attributes hash (for XML generation).
-
#types ⇒ Object
Get page types as an array (handles space-separated values).
Constructor Details
#initialize(attributes = {}) ⇒ Page
Returns a new instance of Page.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/comicinfo/page.rb', line 11 def initialize attributes = {} @image = parse_image(attributes['Image'] || attributes[:image]) @type = Enums::Validators.validate_comic_page_type(attributes['Type'] || attributes[:type]) @double_page = parse_boolean(attributes['DoublePage'] || attributes[:double_page]) @image_size = parse_image_size(attributes['ImageSize'] || attributes[:image_size]) @key = (attributes['Key'] || attributes[:key] || Enums::DEFAULT_STRING).to_s @bookmark = (attributes['Bookmark'] || attributes[:bookmark] || Enums::DEFAULT_STRING).to_s @image_width = parse_image_dimension(attributes['ImageWidth'] || attributes[:image_width], 'ImageWidth') @image_height = parse_image_dimension(attributes['ImageHeight'] || attributes[:image_height], 'ImageHeight') end |
Instance Attribute Details
#bookmark ⇒ Object (readonly)
Page attributes from XSD schema
9 10 11 |
# File 'lib/comicinfo/page.rb', line 9 def bookmark @bookmark end |
#double_page ⇒ Object (readonly)
Page attributes from XSD schema
9 10 11 |
# File 'lib/comicinfo/page.rb', line 9 def double_page @double_page end |
#image ⇒ Object (readonly)
Page attributes from XSD schema
9 10 11 |
# File 'lib/comicinfo/page.rb', line 9 def image @image end |
#image_height ⇒ Object (readonly)
Page attributes from XSD schema
9 10 11 |
# File 'lib/comicinfo/page.rb', line 9 def image_height @image_height end |
#image_size ⇒ Object (readonly)
Page attributes from XSD schema
9 10 11 |
# File 'lib/comicinfo/page.rb', line 9 def image_size @image_size end |
#image_width ⇒ Object (readonly)
Page attributes from XSD schema
9 10 11 |
# File 'lib/comicinfo/page.rb', line 9 def image_width @image_width end |
#key ⇒ Object (readonly)
Page attributes from XSD schema
9 10 11 |
# File 'lib/comicinfo/page.rb', line 9 def key @key end |
#type ⇒ Object (readonly)
Page attributes from XSD schema
9 10 11 |
# File 'lib/comicinfo/page.rb', line 9 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Equality comparison
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/comicinfo/page.rb', line 119 def == other return false unless other.is_a?(Page) @image == other.image && @type == other.type && @double_page == other.double_page && @image_size == other.image_size && @key == other.key && @bookmark == other.bookmark && @image_width == other.image_width && @image_height == other.image_height end |
#aspect_ratio ⇒ Object
Get aspect ratio if dimensions are available
66 67 68 69 70 |
# File 'lib/comicinfo/page.rb', line 66 def aspect_ratio return nil unless dimensions_available? && @image_height != 0 @image_width.to_f / @image_height end |
#bookmarked? ⇒ Boolean
Check if this page has a bookmark
73 74 75 |
# File 'lib/comicinfo/page.rb', line 73 def bookmarked? !@bookmark.empty? end |
#cover? ⇒ Boolean
Check if this page is a cover page
23 24 25 |
# File 'lib/comicinfo/page.rb', line 23 def cover? @type == 'FrontCover' || @type == 'BackCover' || @type == 'InnerCover' end |
#deleted? ⇒ Boolean
Check if this page should be deleted/hidden
33 34 35 |
# File 'lib/comicinfo/page.rb', line 33 def deleted? @type == 'Deleted' end |
#dimensions ⇒ Object
Get image dimensions as a hash
53 54 55 56 57 58 |
# File 'lib/comicinfo/page.rb', line 53 def dimensions { width: @image_width == Enums::DEFAULT_INTEGER ? nil : @image_width, height: @image_height == Enums::DEFAULT_INTEGER ? nil : @image_height } end |
#dimensions_available? ⇒ Boolean
Check if image dimensions are available
61 62 63 |
# File 'lib/comicinfo/page.rb', line 61 def dimensions_available? @image_width != Enums::DEFAULT_INTEGER && @image_height != Enums::DEFAULT_INTEGER end |
#double_page? ⇒ Boolean
Check if this is a double-page spread
38 39 40 |
# File 'lib/comicinfo/page.rb', line 38 def double_page? @double_page end |
#hash ⇒ Object
134 135 136 |
# File 'lib/comicinfo/page.rb', line 134 def hash [@image, @type, @double_page, @image_size, @key, @bookmark, @image_width, @image_height].hash end |
#include_type?(type) ⇒ Boolean
Check if page has a specific type
48 49 50 |
# File 'lib/comicinfo/page.rb', line 48 def include_type? type types.include?(type) end |
#inspect ⇒ Object
Detailed inspection
114 115 116 |
# File 'lib/comicinfo/page.rb', line 114 def inspect "#<ComicInfo::Page #{self}>" end |
#story? ⇒ Boolean
Check if this page is a story page
28 29 30 |
# File 'lib/comicinfo/page.rb', line 28 def story? @type == 'Story' end |
#to_h ⇒ Object
Convert to hash representation
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/comicinfo/page.rb', line 78 def to_h { image: @image, type: @type, double_page: @double_page, image_size: @image_size, key: @key, bookmark: @bookmark, image_width: @image_width, image_height: @image_height } end |
#to_s ⇒ Object
String representation
105 106 107 108 109 110 111 |
# File 'lib/comicinfo/page.rb', line 105 def to_s parts = ["Page #{@image}"] parts << "Type: #{@type}" unless @type == Enums::DEFAULT_PAGE_TYPE parts << 'Double' if @double_page parts << "Bookmark: #{@bookmark}" unless @bookmark.empty? parts.join(', ') end |
#to_xml_attributes ⇒ Object
Convert to XML attributes hash (for XML generation)
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/comicinfo/page.rb', line 92 def to_xml_attributes attrs = { 'Image' => @image.to_s } attrs['Type'] = @type unless @type == Enums::DEFAULT_PAGE_TYPE attrs['DoublePage'] = @double_page.to_s unless @double_page == Enums::DEFAULT_DOUBLE_PAGE attrs['ImageSize'] = @image_size.to_s unless @image_size == Enums::DEFAULT_IMAGE_SIZE attrs['Key'] = @key unless @key.empty? attrs['Bookmark'] = @bookmark unless @bookmark.empty? attrs['ImageWidth'] = @image_width.to_s unless @image_width == Enums::DEFAULT_INTEGER attrs['ImageHeight'] = @image_height.to_s unless @image_height == Enums::DEFAULT_INTEGER attrs end |
#types ⇒ Object
Get page types as an array (handles space-separated values)
43 44 45 |
# File 'lib/comicinfo/page.rb', line 43 def types @type.split(/\s+/) end |