<commit_before>require "lita"

module Lita
  module Handlers
    class Flip < Handler
      FLIPPER = '(╯°□°）╯︵ '.freeze
      FLIPPED_CHARACTERS = {
        '!' => '¡',
        '?' => '¿',
        '6' => '9',
        '9' => '6',
        'a' => 'ɐ',
        'b' => 'q',
        'c' => 'ɔ',
        'd' => 'p',
        'e' => 'ǝ',
        'f' => 'ɟ',
        'g' => 'b',
        'h' => 'ɥ',
        'i' => 'ı',
        'j' => 'ɾ',
        'k' => 'ʞ',
        'l' => 'l',
        'm' => 'ɯ',
        'n' => 'u',
        'o' => 'o',
        'p' => 'd',
        'q' => 'b',
        'r' => 'ɹ',
        's' => 's',
        't' => 'ʇ',
        'u' => 'n',
        'v' => 'ʌ',
        'w' => 'ʍ',
        'x' => 'x',
        'y' => 'ʎ',
        'z' => 'z',
        '<' => '>',
        '>' => '<',
        '(' => ')',
        ')' => '(',
        '[' => ']',
        ']' => '[',
        '/' => '\\',
        '\\' => '/',
        ',' => '\'',
        '\'' => ',',
      }

      FLIPPED_WORDS = {
        'table'      => '┻━┻',
        ':poop:'     => ':icecream:',
        ':icecream:' => ':poop:'
      }

      route %r{\Aflip(?:\s+me)?\s+(.*)\Z}, :flip,
        command: true,
        help: {
          'flip TERM' => 'flips TERM into ɯɹǝʇ'
        }

      def flip(response)
        sentence = response.matches.first.first.downcase

        response.reply "#{ FLIPPER }#{flip_sentence(sentence) }"
      end

      def flip_sentence(sentence)
        sentence.
          split(/\s+/).
          map { |word| flip_word(word) }.
          reverse.
          join(' ')
      end

      def flip_word(word)
        FLIPPED_WORDS.fetch(word) do |w|
          w.chars.map { |char| flip_char(char) }.join.reverse
        end
      end

      def flip_char(char)
        flipped_char = FLIPPED_CHARACTERS[char] unless flipped_char
        return flipped_char unless flipped_char.nil?
        FLIPPED_CHARACTERS.key(char)
      end
    end

    Lita.register_handler(Flip)
  end
end<commit_msg>Simplifying method as per zacstewart's suggestion<commit_after>require "lita"

module Lita
  module Handlers
    class Flip < Handler
      FLIPPER = '(╯°□°）╯︵ '.freeze
      FLIPPED_CHARACTERS = {
        '!' => '¡',
        '?' => '¿',
        '6' => '9',
        '9' => '6',
        'a' => 'ɐ',
        'b' => 'q',
        'c' => 'ɔ',
        'd' => 'p',
        'e' => 'ǝ',
        'f' => 'ɟ',
        'g' => 'b',
        'h' => 'ɥ',
        'i' => 'ı',
        'j' => 'ɾ',
        'k' => 'ʞ',
        'l' => 'l',
        'm' => 'ɯ',
        'n' => 'u',
        'o' => 'o',
        'p' => 'd',
        'q' => 'b',
        'r' => 'ɹ',
        's' => 's',
        't' => 'ʇ',
        'u' => 'n',
        'v' => 'ʌ',
        'w' => 'ʍ',
        'x' => 'x',
        'y' => 'ʎ',
        'z' => 'z',
        '<' => '>',
        '>' => '<',
        '(' => ')',
        ')' => '(',
        '[' => ']',
        ']' => '[',
        '/' => '\\',
        '\\' => '/',
        ',' => '\'',
        '\'' => ',',
      }

      FLIPPED_WORDS = {
        'table'      => '┻━┻',
        ':poop:'     => ':icecream:',
        ':icecream:' => ':poop:'
      }

      route %r{\Aflip(?:\s+me)?\s+(.*)\Z}, :flip,
        command: true,
        help: {
          'flip TERM' => 'flips TERM into ɯɹǝʇ'
        }

      def flip(response)
        sentence = response.matches.first.first.downcase

        response.reply "#{ FLIPPER }#{flip_sentence(sentence) }"
      end

      def flip_sentence(sentence)
        sentence.
          split(/\s+/).
          map { |word| flip_word(word) }.
          reverse.
          join(' ')
      end

      def flip_word(word)
        FLIPPED_WORDS.fetch(word) do |w|
          w.chars.map { |char| flip_char(char) }.join.reverse
        end
      end

      def flip_char(char)
        FLIPPED_CHARACTERS.fetch(char) { FLIPPED_CHARACTERS.key(char) }
      end
    end

    Lita.register_handler(Flip)
  end
end
{'fraction_non_alphanumeric': 0.23798568507157464, 'fraction_numerical': 0.002044989775051125, 'mean_word_length': 1.290983606557377, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 95, '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': '3187842', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1521, 'n_words': 267}