Sha256: 4531afba83c9406c20127e9da6d50c5da271c8899fd3b53dbbec0009d407b6e1

Contents?: true

Size: 735 Bytes

Versions: 2

Compression:

Stored size: 735 Bytes

Contents

require "active_support/concern"

module Himekaminize
  module Filterable
    extend ::ActiveSupport::Concern

    def initialize(markdown)
      @markdown = markdown
      to_lines
      @result ||= Hash.new
    end

    def call
      result[:output] =
        filters.inject(lines) do |output, filter|
          filter.call(output)
        end
    end

    def result
      @result
    end

    private

    def filters
      @filters ||= self.class.filter_classes.map(&:new)
    end

    def markdown
      @markdown
    end

    def lines
      @lines
    end

    def to_lines
      @lines = markdown.lines
    end

    module ClassMethods
      def filter_classes
        raise ::NotImplementedError
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
himekaminize-0.0.4 lib/himekaminize/filterable.rb
himekaminize-0.0.3 lib/himekaminize/filterable.rb