summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/pic.rb
diff options
context:
space:
mode:
authorJonathan Tron <[email protected]>2015-07-04 12:19:37 +0200
committerJonathan Tron <[email protected]>2015-07-04 12:20:57 +0200
commiteb24621d853b42cb2d540955c08cb232dfa3dd71 (patch)
tree04e2a151000fdf9f20ab080cb6e69d0c27a707d3 /lib/axlsx/drawing/pic.rb
parentf27b6415d0dfb1dada0e8e627b3db3bfc1f4f4f9 (diff)
downloadcaxlsx-eb24621d853b42cb2d540955c08cb232dfa3dd71.tar.gz
caxlsx-eb24621d853b42cb2d540955c08cb232dfa3dd71.zip
Add a little bit of doc, remove warning by using attr_reader
Diffstat (limited to 'lib/axlsx/drawing/pic.rb')
-rw-r--r--lib/axlsx/drawing/pic.rb32
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb
index d38d2b6d..275a6d06 100644
--- a/lib/axlsx/drawing/pic.rb
+++ b/lib/axlsx/drawing/pic.rb
@@ -9,12 +9,13 @@ module Axlsx
# Creates a new Pic(ture) object
# @param [Anchor] anchor the anchor that holds this image
- # @option options [String] name
- # @option options [String] descr
- # @option options [String] image_src
- # @option options [Array] start_at
- # @option options [Intger] width
- # @option options [Intger] height
+ # @option options [String] :name
+ # @option options [String] :descr
+ # @option options [String] :image_src
+ # @option options [Array] :start_at
+ # @option options [Integer] :width
+ # @option options [Integer] :height
+ # @option options [Float] :opacity - set the picture opacity, accepts a value between 0.0 and 1.0
def initialize(anchor, options={})
@anchor = anchor
@hyperlink = nil
@@ -23,7 +24,7 @@ module Axlsx
start_at(*options[:start_at]) if options[:start_at]
yield self if block_given?
@picture_locking = PictureLocking.new(options)
- @opacity = (options[:opacity] * 100000).round if options[:opacity] #accepts value beween 0..1
+ @opacity = (options[:opacity] * 100000).round if options[:opacity]
end
# allowed mime types
@@ -51,19 +52,23 @@ module Axlsx
attr_reader :hyperlink
+ # Picture opacity
+ # @return [Fixnum]
+ attr_reader :opacity
+
# sets or updates a hyperlink for this image.
# @param [String] v The href value for the hyper link
# @option options @see Hyperlink#initialize All options available to the Hyperlink class apply - however href will be overridden with the v parameter value.
def hyperlink=(v, options={})
options[:href] = v
- if @hyperlink.is_a?(Hyperlink)
+ if hyperlink.is_a?(Hyperlink)
options.each do |o|
- @hyperlink.send("#{o[0]}=", o[1]) if @hyperlink.respond_to? "#{o[0]}="
+ hyperlink.send("#{o[0]}=", o[1]) if hyperlink.respond_to? "#{o[0]}="
end
else
@hyperlink = Hyperlink.new(self, options)
end
- @hyperlink
+ hyperlink
end
def image_src=(v)
@@ -79,7 +84,6 @@ module Axlsx
# @see descr
def descr=(v) Axlsx::validate_string(v); @descr = v; end
-
# The file name of image_src without any path information
# @return [String]
def file_name
@@ -167,14 +171,14 @@ module Axlsx
str << '<xdr:pic>'
str << '<xdr:nvPicPr>'
str << ('<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">')
- @hyperlink.to_xml_string(str) if @hyperlink.is_a?(Hyperlink)
+ hyperlink.to_xml_string(str) if hyperlink.is_a?(Hyperlink)
str << '</xdr:cNvPr><xdr:cNvPicPr>'
picture_locking.to_xml_string(str)
str << '</xdr:cNvPicPr></xdr:nvPicPr>'
str << '<xdr:blipFill>'
str << ('<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '">')
- if @opacity
- str << "<a:alphaModFix amt=\"#{@opacity}\"/>"
+ if opacity
+ str << "<a:alphaModFix amt=\"#{opacity}\"/>"
end
str << '</a:blip>'
str << '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr>'