Sha256: 54e0b2c0145aba3a1a8aea2f24816ac78387a6b04ce8c04abaec7fab45db49cd

Contents?: true

Size: 1.77 KB

Versions: 19

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

module Pennyworth
  # Processes all steps required to render an Alfred Script Filter response.
  class Processor
    def self.for_encodings
      new loader: Loaders::Encodings.new,
          presenter: Presenters::Encoding,
          serializer: Serializers::Encoding
    end

    def self.for_gems
      new loader: Loaders::Projects.for_ruby_gems,
          presenter: Presenters::Gem,
          serializer: Serializers::Project
    end

    def self.for_http_statuses
      new loader: Loaders::HTTPStatuses.new,
          presenter: Presenters::HTTPStatus,
          serializer: Serializers::HTTPStatus
    end

    def self.for_projects
      new loader: Loaders::Projects.for_git_hub,
          presenter: Presenters::Repository,
          serializer: Serializers::Project
    end

    def self.for_system_signals
      new loader: Loaders::System::Signals.new,
          presenter: Presenters::System::Signal,
          serializer: Serializers::System::Signal
    end

    def self.for_system_errors
      new loader: Loaders::System::Errors.new,
          presenter: Presenters::System::Error,
          serializer: Serializers::System::Error
    end

    def self.for_text
      new loader: Loaders::Text.new, presenter: Presenters::Text, serializer: Serializers::Text
    end

    def initialize steps
      @steps = steps
    end

    def call content = nil
      loader.call(content)
            .map { |record| presenter.new record }
            .sort_by(&:label)
            .map { |record| serializer.new record }
            .then { |records| {items: records.map(&:to_h)} }
    end

    private

    attr_reader :steps

    def loader = steps.fetch(__method__)

    def presenter = steps.fetch(__method__)

    def serializer = steps.fetch(__method__)
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
pennyworth-13.1.0 lib/pennyworth/processor.rb
pennyworth-13.0.1 lib/pennyworth/processor.rb
pennyworth-13.0.0 lib/pennyworth/processor.rb
pennyworth-12.3.1 lib/pennyworth/processor.rb
pennyworth-12.3.0 lib/pennyworth/processor.rb
pennyworth-12.2.0 lib/pennyworth/processor.rb
pennyworth-12.1.0 lib/pennyworth/processor.rb
pennyworth-12.0.2 lib/pennyworth/processor.rb
pennyworth-12.0.1 lib/pennyworth/processor.rb
pennyworth-12.0.0 lib/pennyworth/processor.rb
pennyworth-11.2.2 lib/pennyworth/processor.rb
pennyworth-11.2.1 lib/pennyworth/processor.rb
pennyworth-11.2.0 lib/pennyworth/processor.rb
pennyworth-11.1.3 lib/pennyworth/processor.rb
pennyworth-11.1.2 lib/pennyworth/processor.rb
pennyworth-11.1.1 lib/pennyworth/processor.rb
pennyworth-11.1.0 lib/pennyworth/processor.rb
pennyworth-11.0.1 lib/pennyworth/processor.rb
pennyworth-11.0.0 lib/pennyworth/processor.rb