Module: CultomePlayer

Includes:
Command, Environment, Events, Media, Objects, Player, Plugins, StateChecker, Utils
Included in:
DefaultPlayer
Defined in:
lib/cultome_player.rb,
lib/cultome_player/media.rb,
lib/cultome_player/utils.rb,
lib/cultome_player/events.rb,
lib/cultome_player/player.rb,
lib/cultome_player/command.rb,
lib/cultome_player/objects.rb,
lib/cultome_player/plugins.rb,
lib/cultome_player/version.rb,
lib/cultome_player/environment.rb,
lib/cultome_player/objects/song.rb,
lib/cultome_player/plugins/help.rb,
lib/cultome_player/objects/album.rb,
lib/cultome_player/objects/drive.rb,
lib/cultome_player/objects/genre.rb,
lib/cultome_player/plugins/alias.rb,
lib/cultome_player/state_checker.rb,
lib/cultome_player/objects/artist.rb,
lib/cultome_player/plugins/points.rb,
lib/cultome_player/objects/command.rb,
lib/cultome_player/objects/response.rb,
lib/cultome_player/plugins/gestures.rb,
lib/cultome_player/objects/parameter.rb,
lib/cultome_player/player/interface/basic.rb,
lib/cultome_player/player/interface/builtin_help.rb,
lib/cultome_player/plugins/keyboard_special_keys.rb

Defined Under Namespace

Modules: Command, Environment, Events, Media, Objects, Player, Plugins, StateChecker, Utils Classes: DefaultPlayer

Constant Summary collapse

VERSION =
"2.0.2"

Constants included from Player::Interactive

Player::Interactive::PROMPT

Constants included from Player::Interface::Helper

Player::Interface::Helper::VALID_SONG_ATTR

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StateChecker

#current_album, #current_artist, #current_playlist, #current_song, #paused?, #playback_length, #playback_position, #playing?, #shuffling?, #stopped?

Methods included from Plugins

#clean_plugins, #init_plugins, #plugin_command_sintax, #plugin_config, #plugins_respond_to?

Methods included from Plugins::KeyboardSpecialKeys

#init_plugin_keyboard_special_keys

Methods included from Plugins::Gestures

#init_plugin_gestures

Methods included from Plugins::Points

#init_plugin_points

Methods included from Plugins::Alias

#command_alias, #description_alias, #respond_to?, #sintax_alias, #usage_alias

Methods included from Plugins::Help

#command_help, #description_help, #sintax_help, #usage_help

Methods included from Events

#emit_event, #listeners, #register_listener

Methods included from Media

#extract_from_mp3

Methods included from Player::Adapter

#player_running?

Methods included from Player::Adapter::Mpg123

#fb_in_player, #ff_in_player, #pause_in_player, #play_in_player, #quit_in_player, #repeat_in_player, #resume_in_player, #stop_in_player

Methods included from Player::Playlist

#playlist?, #playlists

Methods included from Player::Interactive

#begin_session, #execute_interactively, #in_session?, #last_command, #session_history, #set_last_command, #terminate_session

Methods included from Player::BuiltinHelp

#description_connect, #description_disconnect, #description_enqueue, #description_fb, #description_ff, #description_next, #description_pause, #description_play, #description_prev, #description_quit, #description_repeat, #description_search, #description_show, #description_shuffle, #description_stop, #usage_connect, #usage_cultome_player, #usage_disconnect, #usage_enqueue, #usage_fb, #usage_ff, #usage_next, #usage_pause, #usage_play, #usage_prev, #usage_quit, #usage_repeat, #usage_search, #usage_show, #usage_shuffle, #usage_stop

Methods included from Player::Interface::Helper

#connect_response_msg, #format_secs, #get_files_in_tree, #get_from_playlists, #get_progress_bar, #get_progress_bar_with_labels, #insert_song, #play_inline?, #play_queue, #player_object, #process_for_search, #search_songs_with, #select_songs_with, #update_song, #whole_library

Methods included from Player::Interface::Extended

#connect, #disconnect, #enqueue, #fb, #ff, #repeat, #search, #show, #shuffle

Methods included from Player::Interface::Basic

#next, #pause, #play, #prev, #quit, #stop

Methods included from Command::Reader

#command_reader, #read_command

Methods included from Command::Processor

#get_command_format, #get_tokens, #identify_tokens, #parse, #validate_command

Methods included from Command::Language

#semantics, #sintax, #token_identities

Methods included from Utils

#arrange_in_columns, #display, #display_over, #ensure_db_schema, #is_true_value?, #recreate_db_schema, #swallow_stdout, #to_display_list, #with_connection

Methods included from Environment

#command_pipe, #config_file, #current_env, #db_adapter, #db_file, #db_log_file, #env_config, #file_types, #load_environment_properties, #mplayer_pipe, #player_config, #prepare_environment, #save_player_configurations, #stdout

Class Method Details

.get_player(env = :user) ⇒ DefaultPlayer

Get an instance of DefaultPlayer

Parameters:

  • env (Symbol) (defaults to: :user)

    The environment from which the configirations will be taken.

Returns:



122
123
124
# File 'lib/cultome_player.rb', line 122

def get_player(env=:user)
  DefaultPlayer.new(env)
end

Instance Method Details

#create_response(type, data) ⇒ Response

Creates a generic response

Parameters:

  • type (Symbol)

    The response type.

  • data (Hash)

    The information that the response will contain.

Returns:

  • (Response)

    Response object with information in form of getter methods.



74
75
76
77
# File 'lib/cultome_player.rb', line 74

def create_response(type, data)
  data[:response_type] = data.keys.first unless data.has_key?(:response_type)
  return Response.new(type, data)
end

#execute(user_input) ⇒ Response

Interpret a user input string as it would be typed in the console.

Parameters:

  • user_input (String)

    The user input.

Returns:

  • (Response)

    Response object with information about command execution.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cultome_player.rb', line 27

def execute(user_input)
  cmds = parse user_input

  seq_success = true # bandera de exito, si un comando de la cadena falla, los siguientes se abortan
  response_seq = cmds.collect do |cmd|
    if seq_success
      # revisamos si es un built in command o un plugin
      action = cmd.action
      plugin_action = "command_#{cmd.action}".to_sym
      action = plugin_action if plugins_respond_to?(cmd.action)

      raise 'invalid command:action unknown' unless respond_to?(action)
      with_connection do
        begin
          emit_event(:before_command, cmd)
          emit_event("before_command_#{action}".to_sym, cmd) if cmd.history?
          r = send(action, cmd)
          emit_event("after_command_#{action}".to_sym, cmd, r) if cmd.history?
          emit_event(:after_command, cmd, r)

          seq_success = false unless r.success?
          r # return response
        rescue Exception => e
          emit_event(:execute_exception, cmd, e)

          if current_env == :test || current_env == :rspec
            display c3("#{e.message}")
            e.backtrace.each{|b| display c3(b) }
          end

          seq_success = false
          s = e.message.split(":")
          failure(message: s[0], details: s[1])
        end
      end
    else # seq_success == false
      nil
    end
  end
  return response_seq.compact # eliminamos los que no corrieron
end

#failure(response) ⇒ Response

Creates a failure response. Handy method for #create_response

Parameters:

  • response (Hash)

    The information that the response will contain.

Returns:

  • (Response)

    Response object with information in form of getter methods.



91
92
93
# File 'lib/cultome_player.rb', line 91

def failure(response)
  create_response(:failure, get_response_params(response))
end

#success(response) ⇒ Response

Creates a success response. Handy method for #create_response

Parameters:

  • response (Hash)

    The information that the response will contain.

Returns:

  • (Response)

    Response object with information in form of getter methods.



83
84
85
# File 'lib/cultome_player.rb', line 83

def success(response)
  create_response(:success, get_response_params(response))
end