Sha256: 204c45a524d2c853ae11b92d51a4e5f45f00ca72447c2321bcb7f459c2660f16

Contents?: true

Size: 1.02 KB

Versions: 16

Compression:

Stored size: 1.02 KB

Contents

require 'link_thumbnailer/model'
require 'link_thumbnailer/image_parser'
require 'link_thumbnailer/image_comparator'
require 'link_thumbnailer/image_validator'

module LinkThumbnailer
  module Models
    class Image < ::LinkThumbnailer::Model

      attr_reader :src, :type, :size

      def initialize(src, size = nil, type = nil)
        @src  = src
        @size = size || parser.size(self)
        @type = type || parser.type(self)
      end

      def to_s
        src.to_s
      end

      def <=>(other)
        comparator.call(other)
      end

      def valid?
        validator.call
      end

      def as_json(*)
        {
          src:  src.to_s,
          size: size,
          type: type
        }
      end

      private

      def parser
        ::LinkThumbnailer::ImageParser
      end

      def validator
        ::LinkThumbnailer::ImageValidator.new(self)
      end

      def comparator
        ::LinkThumbnailer::ImageComparator.new(self)
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
link_thumbnailer-3.0.1 lib/link_thumbnailer/models/image.rb
link_thumbnailer-3.0.0 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.6.1 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.6.0 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.5.2 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.5.1 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.5.0 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.4.0 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.3.2 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.3.1 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.3.0 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.2.3 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.2.2 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.2.1 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.2.0 lib/link_thumbnailer/models/image.rb
link_thumbnailer-2.1.0 lib/link_thumbnailer/models/image.rb