Class: Pennyworth::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/pennyworth/processor.rb

Overview

Processes all steps required to render an Alfred Script Filter response.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steps) ⇒ Processor

Returns a new instance of Processor.



60
61
62
# File 'lib/pennyworth/processor.rb', line 60

def initialize steps
  @steps = steps
end

Class Method Details

.for_encodingsObject



6
7
8
9
10
# File 'lib/pennyworth/processor.rb', line 6

def self.for_encodings
  new loader: Loaders::Encoding.new,
      presenter: Presenters::Encoding,
      serializer: Serializers::Encoding
end

.for_gemsObject



12
13
14
# File 'lib/pennyworth/processor.rb', line 12

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

.for_htmxObject



22
23
24
# File 'lib/pennyworth/processor.rb', line 22

def self.for_htmx
  new loader: Loaders::HTMX.new, presenter: Presenters::HTMX, serializer: Serializers::HTMX
end

.for_http_statusesObject



16
17
18
19
20
# File 'lib/pennyworth/processor.rb', line 16

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

.for_projectsObject



26
27
28
29
30
# File 'lib/pennyworth/processor.rb', line 26

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

.for_standard_errorsObject



38
39
40
41
42
# File 'lib/pennyworth/processor.rb', line 38

def self.for_standard_errors
  new loader: Loaders::StandardError.new,
      presenter: Presenters::StandardError,
      serializer: Serializers::StandardError
end

.for_standard_gemsObject



32
33
34
35
36
# File 'lib/pennyworth/processor.rb', line 32

def self.for_standard_gems
  new loader: Loaders::StandardGem.new,
      presenter: Presenters::StandardGem,
      serializer: Serializers::Project
end

.for_system_errorsObject



44
45
46
47
48
# File 'lib/pennyworth/processor.rb', line 44

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

.for_system_signalsObject



50
51
52
53
54
# File 'lib/pennyworth/processor.rb', line 50

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

.for_textObject



56
57
58
# File 'lib/pennyworth/processor.rb', line 56

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

Instance Method Details

#call(content = nil) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/pennyworth/processor.rb', line 64

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