Sha256: 8d1209e16593ad1ccc8df67286974f4d5717b6ea1daeb2c0f147c51aea0ebc99

Contents?: true

Size: 559 Bytes

Versions: 4

Compression:

Stored size: 559 Bytes

Contents

require "forwardable"
require "galaxy_converter/detector"

module GalaxyConverter
  class Responder
    extend Forwardable

    def_delegators :@detector, :goods, :converter

    def initialize(notes, detector = Detector)
      @questions = notes.select(&:question?)
      @detector = detector.new(notes)
    end

    def call
      @questions.reduce([]) do |acc, note|
        total = total(note)
        acc << note.answer(total)
      end
    end 

    private def total(note)
      converter.call(note.units) * goods.fetch(note.good, 1)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
galaxy_converter-3.1.3 lib/galaxy_converter/responder.rb
galaxy_converter-3.1.2 lib/galaxy_converter/responder.rb
galaxy_converter-3.1.1 lib/galaxy_converter/responder.rb
galaxy_converter-3.0.1 lib/galaxy_converter/responder.rb