Sha256: 1ff3775db9674a5b8db2438048b3b9297b563cd50c9e33262f6807335c701113

Contents?: true

Size: 718 Bytes

Versions: 6

Compression:

Stored size: 718 Bytes

Contents

require "active_support/concern"

module Amakanize
  module Filterable
    extend ::ActiveSupport::Concern

    # @param raw [String]
    def initialize(raw)
      @raw = raw
    end

    # @note Override
    def to_s
      filters.inject(context: {}, output: raw) do |result, filter|
        filter.call(result)
      end[:output]
    end

    private

    # @private
    # @return [Array<Amakanize::Filters::BaseFilter>]
    def filters
      @filters ||= self.class.filter_classes.map(&:new)
    end

    # @private
    # @return [String]
    def raw
      @raw
    end

    module ClassMethods
      # @return [Array<Class>]
      def filter_classes
        raise ::NotImplementedError
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
amakanize-0.6.5 lib/amakanize/filterable.rb
amakanize-0.6.4 lib/amakanize/filterable.rb
amakanize-0.6.3 lib/amakanize/filterable.rb
amakanize-0.6.2 lib/amakanize/filterable.rb
amakanize-0.6.1 lib/amakanize/filterable.rb
amakanize-0.6.0 lib/amakanize/filterable.rb