Class: MountableFileServer::Metadata
- Inherits:
-
Object
- Object
- MountableFileServer::Metadata
- Defined in:
- lib/mountable_file_server/metadata.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(size:, content_type:, width: nil, height: nil) ⇒ Metadata
constructor
A new instance of Metadata.
- #to_h ⇒ Object
Constructor Details
#initialize(size:, content_type:, width: nil, height: nil) ⇒ Metadata
Returns a new instance of Metadata.
7 8 9 10 11 12 |
# File 'lib/mountable_file_server/metadata.rb', line 7 def initialize(size:, content_type:, width: nil, height: nil) @size = size @content_type = content_type @width = width @height = height end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
5 6 7 |
# File 'lib/mountable_file_server/metadata.rb', line 5 def content_type @content_type end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
5 6 7 |
# File 'lib/mountable_file_server/metadata.rb', line 5 def height @height end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'lib/mountable_file_server/metadata.rb', line 5 def size @size end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
5 6 7 |
# File 'lib/mountable_file_server/metadata.rb', line 5 def width @width end |
Class Method Details
.for_path(path) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mountable_file_server/metadata.rb', line 30 def self.for_path(path) parameters = {} parameters[:content_type] = `file --brief --mime-type #{path}`.strip parameters[:size] = File.size(path) if ['image/png', 'image/jpeg', 'image/gif', 'image/tiff'].include?(parameters[:content_type]) dimensions = Dimensions.dimensions(path) parameters[:width] = dimensions[0] parameters[:height] = dimensions[1] end new(**parameters) end |
Instance Method Details
#to_h ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mountable_file_server/metadata.rb', line 14 def to_h hash = { size: size, content_type: content_type } if width && height hash = hash.merge({ height: height, width: width }) end hash end |