Sha256: 6b25fc2cbfa61bc263619767e289d97a58ec3aad8c44c6050289b7a006d43928

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require "core"
require "refinements/strings"

module Pennyworth
  module Presenters
    # Renders Standard Gem records into a compatible format for use in Alfred script filters.
    class StandardGem
      using Refinements::Arrays
      using Refinements::Strings

      def initialize record, inflector: Inflector.new
        @record = record
        @inflector = inflector
      end

      def id = record.fetch :gem

      def label = "#{inflector.call id.titleize} #{version}"

      def subtitle = record.fetch :description

      # :reek:FeatureEnvy
      def version
        versions = record.fetch :versions, Core::EMPTY_HASH
        (versions[:bundled] || versions[:default] || versions).values.first
      end

      def site_url = record.fetch(:sourceRepository, Core::EMPTY_STRING)

      def source_url = record.fetch(:sourceRepository, Core::EMPTY_STRING)

      def issues_url = "https://github.com/ruby/#{id}/issues"

      def versions_url = "https://github.com/ruby/#{id}/tags"

      private

      attr_reader :record, :inflector
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pennyworth-15.4.1 lib/pennyworth/presenters/standard_gem.rb
pennyworth-15.4.0 lib/pennyworth/presenters/standard_gem.rb
pennyworth-15.3.0 lib/pennyworth/presenters/standard_gem.rb
pennyworth-15.2.0 lib/pennyworth/presenters/standard_gem.rb