Sha256: 5dd0716a14705468cb573b850ed5adb48fe19a76d1b008c4cf64aa4dc87f5bcf

Contents?: true

Size: 941 Bytes

Versions: 17

Compression:

Stored size: 941 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EhbrsRubyUtils
  module Bga
    class Game
      class Image
        common_constructor :game, :suffix

        IMAGE_URL_PREFIX = 'https://x.boardgamearena.net/data/gamemedia/'

        # @return [String]
        def fs_object_id
          [game.code, suffix].map(&:parameterize)
        end

        # @param suffix [String]
        # @return [Pathname]
        def local_path
          download_to_cache unless fs_cache.stored?
          fs_cache.content_path.to_pathname
        end

        # @return [Addressable::URI]
        def url
          "#{IMAGE_URL_PREFIX}#{game.code}#{suffix}".to_uri
        end

        private

        # @return [void]
        def download_to_cache
          fs_cache.send(:assert_directory_on_path)
          ::EacEnvs::Http::Request.new.url(url).response.write_body(fs_cache.content_path)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.44.1 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.44.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.41.1 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.41.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.40.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.39.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.38.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.37.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.36.1 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.36.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.35.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.33.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.32.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.31.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.30.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.29.0 lib/ehbrs_ruby_utils/bga/game/image.rb
ehbrs_ruby_utils-0.28.0 lib/ehbrs_ruby_utils/bga/game/image.rb