<commit_before>require 'eventmachine'
require 'em-websocket'
require 'oj'

require_relative '../omx/status'

module Omx
  class Controller

    attr_reader :q, :output_mode

    def initialize(queue=[], opts={})
      @q = queue
      @output_mode = opts[:output_mode] || 'hdmi'
      @player = opts[:player] || Omx::Player.new
    end

    def as_json
      {
        'queue' => @q,
        'output_mode' => @output_mode,
        'now_playing' => Omx::Status.new.to_h
      }
    end

    def react_to(opts)

      # Try and run the action on this controller first.
      if respond_to? opts['action'].to_s
        return if send opts['action'], opts['option']
      end

      # Run commands on the player itself
      if @player.respond_to? opts['action'].to_s
        return if @player.send opts['action']
      end

      # Finally, try and run it directly from the array
      if @q.respond_to? opts['action'].to_s
        return if @q.send opts['action'], opts['filename'] && @q.compact!
      end

    end

    def clear(*args)
      @q.clear
    end

    def change_output(mode)
      {'mode' => "#{@output_mode = mode}"}
    end

    def play_next_if_needed
      if @q.any? && !Omx::Status.new.playing?
        Omx::Player.new.open({filename: @q.shift, audio_out: @output_mode})
      end
    end

  end
end<commit_msg>Brackets<commit_after>require 'eventmachine'
require 'em-websocket'
require 'oj'

require_relative '../omx/status'

module Omx
  class Controller

    attr_reader :q, :output_mode

    def initialize(queue=[], opts={})
      @q = queue
      @output_mode = opts[:output_mode] || 'hdmi'
      @player = opts[:player] || Omx::Player.new
    end

    def as_json
      {
        'queue' => @q,
        'output_mode' => @output_mode,
        'now_playing' => Omx::Status.new.to_h
      }
    end

    def react_to(opts)

      # Try and run the action on this controller first.
      if respond_to? opts['action'].to_s
        return if send opts['action'], opts['option']
      end

      # Run commands on the player itself
      if @player.respond_to? opts['action'].to_s
        return if @player.send opts['action']
      end

      # Finally, try and run it directly from the array
      if @q.respond_to? opts['action'].to_s
        return if @q.send(opts['action'], opts['filename']) && @q.compact!
      end

    end

    def clear(*args)
      @q.clear
    end

    def change_output(mode)
      {'mode' => "#{@output_mode = mode}"}
    end

    def play_next_if_needed
      if @q.any? && !Omx::Status.new.playing?
        Omx::Player.new.open({filename: @q.shift, audio_out: @output_mode})
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.13328313253012047, 'fraction_numerical': 0.0, 'mean_word_length': 2.4328165374677004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3179680', 'n_tokens_mistral': 896, 'n_tokens_neox': 860, 'n_words': 224}