Class: RailsDevtools::ImageAssets::ImageInfo
- Inherits:
-
Object
- Object
- RailsDevtools::ImageAssets::ImageInfo
- Defined in:
- app/models/rails_devtools/image_assets/image_info.rb
Constant Summary collapse
- IMAGE_EXTENSIONS =
Set[ ".jpg", ".jpeg", # JPEG ".png", # PNG ".gif", # GIF ".webp", # WebP ".svg", # SVG ".avif", # AVIF ".ico" # Favicon ].freeze
Instance Method Summary collapse
- #basename ⇒ Object
- #devtools_image_path ⇒ Object
- #extension ⇒ Object
- #file_size ⇒ Object
- #full_path ⇒ Object
- #height ⇒ Object
- #image? ⇒ Boolean
- #image_helper_snippet ⇒ Object
-
#initialize(image_path) ⇒ ImageInfo
constructor
A new instance of ImageInfo.
- #name ⇒ Object
- #valid? ⇒ Boolean
- #width ⇒ Object
Constructor Details
#initialize(image_path) ⇒ ImageInfo
Returns a new instance of ImageInfo.
16 17 18 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 16 def initialize(image_path) @image_path = image_path end |
Instance Method Details
#basename ⇒ Object
32 33 34 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 32 def basename @basename ||= File.basename(@image_path) end |
#devtools_image_path ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 52 def devtools_image_path return @devtools_image_path if defined?(@devtools_image_path) matching_path = asset_config.paths.find { |asset_path| @image_path.start_with?(asset_path) } matching_base = Pathname.new(matching_path).join(asset_config.implicit_path) asset_path = Pathname.new(@image_path) @devtools_image_path = asset_path .relative_path_from(matching_base) .to_s.sub("../", "") end |
#extension ⇒ Object
40 41 42 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 40 def extension File.extname(@image_path).downcase end |
#file_size ⇒ Object
44 45 46 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 44 def file_size @file_size ||= FastImage.new(@image_path).content_length end |
#full_path ⇒ Object
20 21 22 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 20 def full_path @image_path end |
#height ⇒ Object
68 69 70 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 68 def height size[1] end |
#image? ⇒ Boolean
28 29 30 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 28 def image? FastImage.type(@image_path).present? end |
#image_helper_snippet ⇒ Object
48 49 50 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 48 def image_helper_snippet "#{asset_config.helper_snippet}(\"#{devtools_image_path}\")" end |
#name ⇒ Object
36 37 38 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 36 def name basename.split(".").first end |
#valid? ⇒ Boolean
24 25 26 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 24 def valid? File.file?(@image_path) && image? end |
#width ⇒ Object
64 65 66 |
# File 'app/models/rails_devtools/image_assets/image_info.rb', line 64 def width size[0] end |