Class: PureDocx::XmlGenerators::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/puredocx/xml_generators/image.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#content, #rels_constructor

Instance Method Summary collapse

Constructor Details

#initialize(image_path, rels_constructor, arguments = {}) ⇒ Image

Returns a new instance of Image.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/puredocx/xml_generators/image.rb', line 13

def initialize(image_path, rels_constructor, arguments = {})
  super(nil, rels_constructor)
  @image_path       = image_path
  @image_name       = File.basename(image_path)
  ensure_file!
  @width            = arguments[:width]
  @height           = arguments[:height]
  @in_header        = arguments[:in_header]
  @align            = arguments[:align]
  @rels_id          = "rId#{appropriated_rels_size}"
  @size_constructor = PureDocx::Constructors::ImageSize.new(
    user_params: [width, height],
    real_params: FastImage.size(image_path)
  )
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



4
5
6
# File 'lib/puredocx/xml_generators/image.rb', line 4

def align
  @align
end

#heightObject (readonly)

Returns the value of attribute height.



4
5
6
# File 'lib/puredocx/xml_generators/image.rb', line 4

def height
  @height
end

#image_nameObject (readonly)

Returns the value of attribute image_name.



4
5
6
# File 'lib/puredocx/xml_generators/image.rb', line 4

def image_name
  @image_name
end

#image_pathObject (readonly)

Returns the value of attribute image_path.



4
5
6
# File 'lib/puredocx/xml_generators/image.rb', line 4

def image_path
  @image_path
end

#in_headerObject (readonly)

Returns the value of attribute in_header.



4
5
6
# File 'lib/puredocx/xml_generators/image.rb', line 4

def in_header
  @in_header
end

#rels_idObject (readonly)

Returns the value of attribute rels_id.



4
5
6
# File 'lib/puredocx/xml_generators/image.rb', line 4

def rels_id
  @rels_id
end

#size_constructorObject (readonly)

Returns the value of attribute size_constructor.



4
5
6
# File 'lib/puredocx/xml_generators/image.rb', line 4

def size_constructor
  @size_constructor
end

#widthObject (readonly)

Returns the value of attribute width.



4
5
6
# File 'lib/puredocx/xml_generators/image.rb', line 4

def width
  @width
end

Instance Method Details

#paramsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/puredocx/xml_generators/image.rb', line 34

def params
  align_params = { horizontal: '', vertical: '' }
  align_params.merge! prepare_align_params(align) if align
  {
    '{WIDTH}'            => size_constructor.prepare_size[:width],
    '{HEIGHT}'           => size_constructor.prepare_size[:height],
    '{RID}'              => rels_id,
    '{NAME}'             => image_name,
    '{UNIQUE_NAME}'      => uniq_name(image_name),
    '{HORIZONTAL_ALIGN}' => align_params[:horizontal],
    '{VERTICAL_ALIGN}'   => align_params[:vertical]
  }
end

#templateObject



48
49
50
51
# File 'lib/puredocx/xml_generators/image.rb', line 48

def template
  return File.read(DocArchive.template_path('float_image.xml')) if align&.any?
  File.read(DocArchive.template_path('image.xml'))
end

#xmlObject



29
30
31
32
# File 'lib/puredocx/xml_generators/image.rb', line 29

def xml
  add_image_rels
  super
end