<commit_before>require 'gtk3'
require "mireru/logger"
require "mireru/window"
require "mireru/container"

module Mireru
  module Command
    class Mireru
      USAGE = "Usage: mireru [FILE...]"

      class << self
        def run(*arguments)
          new.run(arguments)
        end
      end

      def initialize
        @logger = ::Mireru::Logger.new
      end

      def run(arguments)
        if arguments.empty?
          files = Dir.glob("*")
          file_container = ::Mireru::Container.new(files)
        elsif /\A(-h|--help)\z/ =~ arguments[0]
          message = <<-EOM
#{USAGE}
  If no argument, then search current directory.
Keybind:
  n: next
  p: prev
  q: quit
          EOM
          @logger.info(message)
          exit(true)
        else
          files = arguments
          file_container = ::Mireru::Container.new(files)
        end

        if file_container.empty?
          message = <<-EOM
Warning: valid file not found.
#{USAGE}
Support file types: png, gif, jpeg(jpg). The others are...yet.
          EOM
          @logger.error(message)
          exit(false)
        end

        file = file_container.shift

        window = ::Mireru::Window.new
        window.add_from_file(file)

        window.signal_connect("key_press_event") do |w, e|
          case e.keyval
          when Gdk::Keyval::GDK_KEY_n
            file = file_container.shift(file)
            window.add_from_file(file)
          when Gdk::Keyval::GDK_KEY_p
            file = file_container.pop(file)
            window.add_from_file(file)
          when Gdk::Keyval::GDK_KEY_r
            window.add_from_file(file)
          when Gdk::Keyval::GDK_KEY_q
            Gtk.main_quit
          end
        end

        window.signal_connect("destroy") do
          Gtk.main_quit
        end

        Gtk.main
      end
    end
  end
end
<commit_msg>Extract mehtods<commit_after>require 'gtk3'
require "mireru/logger"
require "mireru/window"
require "mireru/container"

module Mireru
  module Command
    class Mireru
      USAGE = "Usage: mireru [FILE...]"

      class << self
        def run(*arguments)
          new.run(arguments)
        end
      end

      def initialize
        @logger = ::Mireru::Logger.new
      end

      def run(arguments)
        if arguments.empty?
          files = Dir.glob("*")
          file_container = ::Mireru::Container.new(files)
        elsif /\A(-h|--help)\z/ =~ arguments[0]
          write_help_message
          exit(true)
        else
          files = arguments
          file_container = ::Mireru::Container.new(files)
        end

        if file_container.empty?
          write_empty_message
          exit(false)
        end

        file = file_container.shift

        window = ::Mireru::Window.new
        window.add_from_file(file)

        window.signal_connect("key_press_event") do |w, e|
          case e.keyval
          when Gdk::Keyval::GDK_KEY_n
            file = file_container.shift(file)
            window.add_from_file(file)
          when Gdk::Keyval::GDK_KEY_p
            file = file_container.pop(file)
            window.add_from_file(file)
          when Gdk::Keyval::GDK_KEY_r
            window.add_from_file(file)
          when Gdk::Keyval::GDK_KEY_q
            Gtk.main_quit
          end
        end

        window.signal_connect("destroy") do
          Gtk.main_quit
        end

        Gtk.main
      end

      private
      def write_help_message
        message = <<-EOM
#{USAGE}
  If no argument, then search current directory.
Keybind:
  n: next
  p: prev
  q: quit
        EOM
        @logger.info(message)
      end

      def write_empty_message
        message = <<-EOM
Warning: valid file not found.
#{USAGE}
Support file types: png, gif, jpeg(jpg). The others are...yet.
        EOM
        @logger.error(message)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09734513274336283, 'fraction_numerical': 0.001041124414367517, 'mean_word_length': 1.7747292418772562, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, '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': '4412641', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1197, 'n_words': 266}