<commit_before>require 'capybara'
require 'capybara/poltergeist'

module Valanga
  class Client
    LOGIN_PAGE  = "https://p.eagate.573.jp/gate/p/login.html"
    MUSIC_INDEX = "https://p.eagate.573.jp/game/reflec/groovin/p/music/index.html"

    attr_reader :session

    def initialize(username, password)
      Capybara.register_driver :poltergeist do |app|
        Capybara::Poltergeist::Driver.new(app)
      end

      @session = Capybara::Session.new(:poltergeist)

      login!(username, password)
    end

    private

    def login!(username, password)
      @session.visit LOGIN_PAGE

      @session.fill_in 'KID', with: username
      @session.fill_in 'pass', with: password

      @session.click_on "規約に同意してログイン"

      unless successful_login?
        raise LoginError, session.find(:xpath, '//div[@class="error_text_box"]/p').text
      end
    end

    def successful_login?
      @session.current_path == "/gate/p/mypage/index.html"
    end
  end
end<commit_msg>Refactor<commit_after>require 'capybara'
require 'capybara/poltergeist'

module Valanga
  class Client
    LOGIN_PAGE  = "https://p.eagate.573.jp/gate/p/login.html"
    MUSIC_INDEX = "https://p.eagate.573.jp/game/reflec/groovin/p/music/index.html"

    attr_reader :session

    def initialize(username, password)
      Capybara.register_driver :poltergeist do |app|
        Capybara::Poltergeist::Driver.new(app)
      end

      @session = Capybara::Session.new(:poltergeist)

      login!(username, password)
    end

    private

    def login!(username, password)
      @session.visit LOGIN_PAGE

      @session.fill_in 'KID', with: username
      @session.fill_in '<PASSWORD>', with: password

      @session.click_on "規約に同意してログイン"

      unless @session.current_path == "/gate/p/mypage/index.html"
        raise LoginError, session.find(:xpath, '//div[@class="error_text_box"]/p').text
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1232876712328767, 'fraction_numerical': 0.006322444678609062, 'mean_word_length': 3.1103896103896105, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 4, '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': '76382', 'n_tokens_mistral': 694, 'n_tokens_neox': 659, 'n_words': 113}