<commit_before>module Play

  # The User does things with Play. These are usually employees who try to
  # request songs to be played, but usually request crap like <NAME>.
  #
  # redis:
  #
  #   play:users                - A Set of all user IDs.
  #   play:users:#{login}:email - The String email for the given `login`.
  #   play:users:#{login}:stars - A Set of all Song `permanent_id`s that have
  #                               been starred by `login`.
  class User

    # The redis key to stash User data.
    KEY = 'play:users'

    # Public: The username of the user's GitHub account.
    attr_accessor :login

    # Public: The public email address listed on GitHub.
    attr_accessor :email

    # Public: Initializes a User.
    #
    # login - The String login of their GitHub account.
    # email - The String email address of their GitHub account.
    #
    # Returns the User.
    def initialize(login,email)
      @login = login.downcase
      @email = email
    end

    # Public: Create a User.
    #
    # login - The String login of their GitHub account.
    # email - The String email address of their GitHub account.
    #
    # Returns the User.
    def self.create(login,email)
      User.new(login,email).save
    end

    # Public: Finds a User.
    #
    # login - The String login.
    #
    # Returns the User, nil if no User found.
    def self.find(login)
      login.downcase!
      return nil if !$redis.sismember(KEY, login)
      email = $redis.get "#{KEY}:#{login}:email"

      User.new(login,email)
    end

    # Public: Saves the User.
    #
    # Returns itself.
    def save
      $redis.sadd KEY, login
      $redis.set  "#{KEY}:#{login}:email", email
      self
    end

    # Public: The MD5 hash of the user's email account. Used for showing their
    # Gravatar.
    #
    # Returns the String MD5 hash.
    def gravatar_id
      Digest::MD5.hexdigest(email) if email
    end

    # Public: A User's saved songs.
    #
    # Returns an Array of Songs.
    def stars
      stars = $redis.smembers("#{KEY}:#{login}:stars")
      stars.map do |id|
        Song.find(id)
      end
    end

    # Public: Did this user star this song?
    #
    # song - The Song.
    #
    # Returns a Boolean value.
    def starred?(song)
      $redis.smembers("${KEY}:#{login}:stars").include?(song.id)
    end

    # Public: Stars a song. Likes a song. Saves a song.
    #
    # song - The Song to star.
    #
    # Returns true when saved.
    def star(song)
      $redis.sadd("#{KEY}:#{login}:stars",song.id)
      true
    end

    # Public: Removes a star.
    #
    # song - The Song to unstar.
    #
    # Returns true when saved.
    def unstar(song)
      $redis.srem("#{KEY}:#{login}:stars",song.id)
      true
    end

  end<commit_msg>someone must've had a case of the mondays<commit_after>module Play

  # The User does things with Play. These are usually employees who try to
  # request songs to be played, but usually request crap like <NAME>.
  #
  # redis:
  #
  #   play:users                - A Set of all user IDs.
  #   play:users:#{login}:email - The String email for the given `login`.
  #   play:users:#{login}:stars - A Set of all Song `permanent_id`s that have
  #                               been starred by `login`.
  class User

    # The redis key to stash User data.
    KEY = 'play:users'

    # Public: The username of the user's GitHub account.
    attr_accessor :login

    # Public: The public email address listed on GitHub.
    attr_accessor :email

    # Public: Initializes a User.
    #
    # login - The String login of their GitHub account.
    # email - The String email address of their GitHub account.
    #
    # Returns the User.
    def initialize(login,email)
      @login = login.downcase
      @email = email
    end

    # Public: Create a User.
    #
    # login - The String login of their GitHub account.
    # email - The String email address of their GitHub account.
    #
    # Returns the User.
    def self.create(login,email)
      User.new(login,email).save
    end

    # Public: Finds a User.
    #
    # login - The String login.
    #
    # Returns the User, nil if no User found.
    def self.find(login)
      login.downcase!
      return nil if !$redis.sismember(KEY, login)
      email = $redis.get "#{KEY}:#{login}:email"

      User.new(login,email)
    end

    # Public: Saves the User.
    #
    # Returns itself.
    def save
      $redis.sadd KEY, login
      $redis.set  "#{KEY}:#{login}:email", email
      self
    end

    # Public: The MD5 hash of the user's email account. Used for showing their
    # Gravatar.
    #
    # Returns the String MD5 hash.
    def gravatar_id
      Digest::MD5.hexdigest(email) if email
    end

    # Public: A User's saved songs.
    #
    # Returns an Array of Songs.
    def stars
      stars = $redis.smembers("#{KEY}:#{login}:stars")
      stars.map do |id|
        Song.find(id)
      end
    end

    # Public: Did this user star this song?
    #
    # song - The Song.
    #
    # Returns a Boolean value.
    def starred?(song)
      $redis.smembers("#{KEY}:#{login}:stars").include?(song.id)
    end

    # Public: Stars a song. Likes a song. Saves a song.
    #
    # song - The Song to star.
    #
    # Returns true when saved.
    def star(song)
      $redis.sadd("#{KEY}:#{login}:stars",song.id)
      true
    end

    # Public: Removes a star.
    #
    # song - The Song to unstar.
    #
    # Returns true when saved.
    def unstar(song)
      $redis.srem("#{KEY}:#{login}:stars",song.id)
      true
    end

  end
{'fraction_non_alphanumeric': 0.10551773557864565, 'fraction_numerical': 0.0010748835542816195, 'mean_word_length': 2.05750273822563, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2925354', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1760, 'n_words': 598}