Class: Uniword::Images::ImageInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/images/image_info.rb

Overview

Value object describing a single image in a document.

Immutable snapshot of image metadata: name, path, content type, byte size, and pixel dimensions (when available).

Examples:

Create from raw data

info = ImageInfo.new(
  name: "image1.png",
  path: "word/media/image1.png",
  content_type: "image/png",
  size: 4782,
  width: 200,
  height: 150
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, path:, content_type:, size:, width: nil, height: nil) ⇒ ImageInfo

Returns a new instance of ImageInfo.

Parameters:

  • name (String)

    File name (e.g., “image1.png”)

  • path (String)

    Full path within the package (e.g., “word/media/image1.png”)

  • content_type (String)

    MIME type (e.g., “image/png”)

  • size (Integer)

    File size in bytes

  • width (Integer, nil) (defaults to: nil)

    Pixel width

  • height (Integer, nil) (defaults to: nil)

    Pixel height



28
29
30
31
32
33
34
35
36
37
# File 'lib/uniword/images/image_info.rb', line 28

def initialize(name:, path:, content_type:, size:, width: nil,
height: nil)
  @name = name
  @path = path
  @content_type = content_type
  @size = size
  @width = width
  @height = height
  freeze
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



20
21
22
# File 'lib/uniword/images/image_info.rb', line 20

def content_type
  @content_type
end

#heightObject (readonly)

Returns the value of attribute height.



20
21
22
# File 'lib/uniword/images/image_info.rb', line 20

def height
  @height
end

#nameObject (readonly)

Returns the value of attribute name.



20
21
22
# File 'lib/uniword/images/image_info.rb', line 20

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/uniword/images/image_info.rb', line 20

def path
  @path
end

#sizeObject (readonly)

Returns the value of attribute size.



20
21
22
# File 'lib/uniword/images/image_info.rb', line 20

def size
  @size
end

#widthObject (readonly)

Returns the value of attribute width.



20
21
22
# File 'lib/uniword/images/image_info.rb', line 20

def width
  @width
end

Instance Method Details

#to_sString

Human-readable representation.

Returns:

  • (String)


42
43
44
45
# File 'lib/uniword/images/image_info.rb', line 42

def to_s
  dims = width && height ? " #{width}x#{height}" : ""
  "#{name} (#{content_type}, #{size} bytes#{dims})"
end