Sha256: 1d4dcf9a8a6743c6d51ec92e23dc570d836adacbc49f7f1939f32411de702658

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

module Amakanize
  module Filters
    class ObviousVolumeNumberDeletionFilter < BaseFilter
      PATTERN = Regexp.union(
        /\s*#{::Amakanize::PATTERN_OF_VOLUME_PREFIX}?#{::Amakanize::PATTERN_OF_NUMERIC_CHARACTERS}(?:話|巻|版).*/,
        /\s+#{::Amakanize::PATTERN_OF_VOLUME_PREFIX}?#{::Amakanize::PATTERN_OF_NUMERIC_CHARACTERS}(?:話|巻|版)?:\s+.*/,
        /\s+#{::Amakanize::PATTERN_OF_VOLUME_PREFIX}#{::Amakanize::PATTERN_OF_NUMERIC_CHARACTERS}\s+.*/,
        /\s+Lv\.?\s*#{::Amakanize::PATTERN_OF_NUMERIC_CHARACTERS}(?:\s+.*|\z)/,
        /\s*\(#{::Amakanize::PATTERN_OF_VOLUME_PREFIX}?#{::Amakanize::PATTERN_OF_NUMERIC_CHARACTERS}\).*/,
        /\s*\d+年\s*\d+\s*(?:月|\/\d+\s*)号.*/,
        /\s*\d{4}\s*(?:AUTUMN|SPRING|SUMMER|WINTER)/,
      )

      # @note Override
      # @param output [String] e.g. `"刀語 第十一話 毒刀・鍍"`, `"アニウッド大通り 1: アニメ監督一家物語"`
      # @return [Hash] e.g. `"刀語"`, `"アニウッド大通り"`
      def call(context:, output:)
        unless context[:volume_number_removed]
          output = output.sub(PATTERN) do
            context[:volume_number_removed] = true
            ""
          end
        end
        {
          context: context,
          output: output,
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
amakanize-0.5.1 lib/amakanize/filters/obvious_volume_number_deletion_filter.rb