Sha256: f950de82de675baced19121463b8b2ea76129ebda7bb13b9345b29573cfd3230

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require "core"
require "refinements/string"

module Pennyworth
  module Presenters
    # Shapes a standard gem record for serialization.
    class StandardGem
      using Refinements::Array
      using Refinements::String

      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

      def version
        versions = record.fetch :versions, Core::EMPTY_HASH
        bundled, defaults = versions.values_at :bundled, :default

        (bundled || defaults || 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

6 entries across 6 versions & 1 rubygems

Version Path
pennyworth-17.8.0 lib/pennyworth/presenters/standard_gem.rb
pennyworth-17.7.0 lib/pennyworth/presenters/standard_gem.rb
pennyworth-17.6.0 lib/pennyworth/presenters/standard_gem.rb
pennyworth-17.5.0 lib/pennyworth/presenters/standard_gem.rb
pennyworth-17.4.1 lib/pennyworth/presenters/standard_gem.rb
pennyworth-17.4.0 lib/pennyworth/presenters/standard_gem.rb