<commit_before>module DragonflyLibvips
  module Processors
    class Thumb
      OPERATORS = '><'.freeze
      RESIZE_GEOMETRY = /\A\d*x\d*[#{OPERATORS}]?\z/ # e.g. '300x200>'

      def call(content, geometry, opts = {})
        image_properties = content.analyse(:image_properties)
        content.process!(:vipsthumbnail, args_for_geometry(geometry, image_properties), opts)
      end

      def update_url(url_attributes, _geometry, opts = {})
        format = opts['format']
        url_attributes.ext = format if format
      end

      def args_for_geometry(geometry, image_properties)
        case geometry
        when RESIZE_GEOMETRY then resize_args(geometry, image_properties)
        else raise ArgumentError, "Didn't recognise the geometry string #{geometry}"
        end
      end

      private

      def resize_args(geometry, image_properties)<commit_msg>allow args to vipsthumbnail<commit_after>module DragonflyLibvips
  module Processors
    class Thumb
      OPERATORS = '><'.freeze
      RESIZE_GEOMETRY = /\A\d*x\d*[#{OPERATORS}]?\z/ # e.g. '300x200>'

      def call(content, geometry, opts = {})
        image_properties = content.analyse(:image_properties)
        args = [args_for_geometry(geometry, image_properties), opts['args']].compact.join(' ')
        content.process!(:vipsthumbnail, args, opts)
      end

      def update_url(url_attributes, _geometry, opts = {})
        format = opts['format']
        url_attributes.ext = format if format
      end

      def args_for_geometry(geometry, image_properties)
        case geometry
        when RESIZE_GEOMETRY then resize_args(geometry, image_properties)
        else raise ArgumentError, "Didn't recognise the geometry string #{geometry}"
        end
      end

      private

      def resize_args(geometry, image_properties)
{'fraction_non_alphanumeric': 0.09812568908489526, 'fraction_numerical': 0.006615214994487321, 'mean_word_length': 3.0423162583518932, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1776025', 'n_tokens_mistral': 563, 'n_tokens_neox': 530, 'n_words': 123}