Sha256: 8519a2eeb44455438660fa2eb753c7333d38ec5583ad195edd8375b036f6bb17

Contents?: true

Size: 887 Bytes

Versions: 6

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

module Pennyworth
  module Serializers
    # Serializes a HTTP status presenter for parsing by Alfred script filters.
    class HTTPStatus
      def initialize presenter
        @presenter = presenter
      end

      def to_h
        {
          uid: id,
          title: code,
          subtitle: label,
          arg: presenter.symbol,
          mods: modifications,
          text: {copy: "#{code} #{label}", largetype: "#{code} #{label}"}
        }
      end

      private

      attr_reader :presenter

      def id = presenter.id

      def code = presenter.code

      def label = presenter.label

      def modifications
        {
          control: {subtitle: "Copy code.", arg: id},
          alt: {subtitle: "Copy label.", arg: label},
          cmd: {subtitle: "View documentation.", arg: presenter.url}
        }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pennyworth-17.8.0 lib/pennyworth/serializers/http_status.rb
pennyworth-17.7.0 lib/pennyworth/serializers/http_status.rb
pennyworth-17.6.0 lib/pennyworth/serializers/http_status.rb
pennyworth-17.5.0 lib/pennyworth/serializers/http_status.rb
pennyworth-17.4.1 lib/pennyworth/serializers/http_status.rb
pennyworth-17.4.0 lib/pennyworth/serializers/http_status.rb