Sha256: 97951b9bca72718ab203a9c6173e6f93bb76caccafaa445f52ef8342d9e6208c

Contents?: true

Size: 1.08 KB

Versions: 11

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
        {
          control: modification(presenter.changes_url, "View changes."),
          alt: modification(presenter.source_url, "View source."),
          cmd: modification(presenter.issues_url, "View issues.")
        }
      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

11 entries across 11 versions & 1 rubygems

Version Path
pennyworth-12.0.1 lib/pennyworth/serializers/project.rb
pennyworth-12.0.0 lib/pennyworth/serializers/project.rb
pennyworth-11.2.2 lib/pennyworth/serializers/project.rb
pennyworth-11.2.1 lib/pennyworth/serializers/project.rb
pennyworth-11.2.0 lib/pennyworth/serializers/project.rb
pennyworth-11.1.3 lib/pennyworth/serializers/project.rb
pennyworth-11.1.2 lib/pennyworth/serializers/project.rb
pennyworth-11.1.1 lib/pennyworth/serializers/project.rb
pennyworth-11.1.0 lib/pennyworth/serializers/project.rb
pennyworth-11.0.1 lib/pennyworth/serializers/project.rb
pennyworth-11.0.0 lib/pennyworth/serializers/project.rb