Sha256: 0dce8603279cf39b6d6760c38e9c99f612401ee22f88c3f5a5698a639d196348

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Pennyworth
  module Serializers
    # Serializes a project into a compatible format for parsing within Alfred script filters.
    class Project
      def initialize presenter
        @presenter = presenter
      end

      def to_h
        {
          uid: presenter.id,
          title: presenter.label,
          subtitle: presenter.subtitle,
          arg: site_url,
          quicklookurl: site_url,
          mods: modifications,
          text: text
        }
      end

      private

      attr_reader :presenter

      def modifications
        {
          alt: modification(presenter.source_url, "View source."),
          cmd: modification(presenter.issues_url, "View issues."),
          control: modification(presenter.versions_url, "View versions.")
        }
      end

      def modification argument, subtitle
        {
          subtitle: subtitle,
          arg: argument
        }
      end

      def text
        {
          copy: site_url,
          largetype: site_url
        }
      end

      def site_url = presenter.site_url
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pennyworth-12.1.0 lib/pennyworth/serializers/project.rb
pennyworth-12.0.2 lib/pennyworth/serializers/project.rb