Class: Html2Odt::Image
- Inherits:
-
Object
- Object
- Html2Odt::Image
- Defined in:
- lib/html2odt/image.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #angle ⇒ Object
- #extension ⇒ Object
- #height ⇒ Object
-
#initialize(target_base) ⇒ Image
constructor
A new instance of Image.
- #mime_type ⇒ Object
- #target ⇒ Object
- #type ⇒ Object
- #valid? ⇒ Boolean
- #width ⇒ Object
Constructor Details
#initialize(target_base) ⇒ Image
Returns a new instance of Image.
4 5 6 7 |
# File 'lib/html2odt/image.rb', line 4 def initialize(target_base) @target_base = target_base @valid = nil end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
2 3 4 |
# File 'lib/html2odt/image.rb', line 2 def source @source end |
Instance Method Details
#angle ⇒ Object
85 86 87 88 89 |
# File 'lib/html2odt/image.rb', line 85 def angle return unless valid? @angle end |
#extension ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/html2odt/image.rb', line 57 def extension return unless valid? if type == :jpeg "jpg" else type end end |
#height ⇒ Object
79 80 81 82 83 |
# File 'lib/html2odt/image.rb', line 79 def height return unless valid? @height end |
#mime_type ⇒ Object
67 68 69 70 71 |
# File 'lib/html2odt/image.rb', line 67 def mime_type return unless valid? "image/#{type}" end |
#target ⇒ Object
91 92 93 94 95 |
# File 'lib/html2odt/image.rb', line 91 def target return unless valid? "Pictures/#{@target_base}.#{extension}" end |
#type ⇒ Object
53 54 55 |
# File 'lib/html2odt/image.rb', line 53 def type valid? ? @type : nil end |
#valid? ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/html2odt/image.rb', line 20 def valid? return false if source.nil? or !File.readable?(source) if @valid.nil? File.open(source, "rb") do |io| Dimensions(io) io.extend Html2Odt::DimensionsPatches # Interacting with Dimensions::Reader directly to # # a) avoid reading the file multiple times # b) get type info io.send :peek reader = io.instance_variable_get :@reader if reader.type && reader.width && reader.height @type = reader.type @width = reader.width @height = reader.height @angle = reader.angle @valid = true else @valid = false end end end @valid end |
#width ⇒ Object
73 74 75 76 77 |
# File 'lib/html2odt/image.rb', line 73 def width return unless valid? @width end |