Sha256: fcc27b272dfae0231d01c1bf3dcf2c2c3f3f9e05ecc3bbc2a6e566386d0f35ad

Contents?: true

Size: 1.16 KB

Versions: 16

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module KepplerFrontend
  module Utils
    # CodeHandler
    class FileFormat
      def initialize; end

      def folders
        %w[audios fonts images videos html javascripts stylesheets]
      end

      def formats
        {
          audios: ['.mp3'],
          fonts: ['.eot', '.otf', '.ttf', '.woff', '.woff2'],
          images: ['.jpg', '.jpeg', '.png', '.svg', '.gif', '.tiff', '.bmp'],
          videos: ['.mp4', '.mpeg', '.webm', '.m4v'],
          html: ['.html'],
          javascripts: ['.js', '.coffee', '.json'],
          stylesheets: ['.css', '.scss', '.sass']
        }
      end

      def folder(file)
        content_type = File.extname(file)
        result = ''
        formats.each do |key, value|
          result = key.to_s if value.include?(content_type)
        end
        result
      end

      def size(size)
        units = %w[B Kb Mb Gb Tb Pb Eb]
        return '0.0 B' if size.zero?
        exp = (Math.log(size) / Math.log(1024)).to_i
        exp = 6 if exp > 6
        result = (size.to_f / 1024 * exp).round(1)
        format('%<result>s %<units>s', result: result, units: units[exp])
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
keppler-2.1.22 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.21 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.20 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.19 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.18 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.17 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.16 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.15 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.14 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.13 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.12 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.11 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.10 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.9 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.8 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb
keppler-2.1.7 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/file_format.rb