Sha256: 0ddb85d56658bd31b41ef1cadfa3b9f2e60af08ff3ec84567da9af9581963db8

Contents?: true

Size: 1.03 KB

Versions: 9

Compression:

Stored size: 1.03 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
        @type = type || parser.type
      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
        @parser ||= ::LinkThumbnailer::ImageParser.new(src)
      end

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

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

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
link_thumbnailer-3.3.1 lib/link_thumbnailer/models/image.rb
link_thumbnailer-3.3.0 lib/link_thumbnailer/models/image.rb
link_thumbnailer-3.2.1 lib/link_thumbnailer/models/image.rb
link_thumbnailer-3.2.0 lib/link_thumbnailer/models/image.rb
link_thumbnailer-3.1.2 lib/link_thumbnailer/models/image.rb
link_thumbnailer-3.1.1 lib/link_thumbnailer/models/image.rb
link_thumbnailer-3.1.0 lib/link_thumbnailer/models/image.rb
link_thumbnailer-3.0.3 lib/link_thumbnailer/models/image.rb
link_thumbnailer-3.0.2 lib/link_thumbnailer/models/image.rb