cultome_player 2.0.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -79
  3. data/Rakefile +38 -4
  4. data/bin/cultome_player +16 -4
  5. data/config/environment.yml +4 -0
  6. data/cultome_player.gemspec +8 -1
  7. data/lib/cultome_player.rb +45 -19
  8. data/lib/cultome_player/command/language.rb +3 -4
  9. data/lib/cultome_player/command/processor.rb +9 -7
  10. data/lib/cultome_player/command/reader.rb +11 -2
  11. data/lib/cultome_player/environment.rb +21 -13
  12. data/lib/cultome_player/events.rb +7 -7
  13. data/lib/cultome_player/objects/album.rb +9 -2
  14. data/lib/cultome_player/objects/artist.rb +9 -2
  15. data/lib/cultome_player/objects/command.rb +10 -1
  16. data/lib/cultome_player/objects/drive.rb +4 -1
  17. data/lib/cultome_player/objects/genre.rb +4 -1
  18. data/lib/cultome_player/objects/parameter.rb +21 -1
  19. data/lib/cultome_player/objects/response.rb +5 -1
  20. data/lib/cultome_player/objects/song.rb +9 -4
  21. data/lib/cultome_player/player/adapter/mpg123.rb +3 -4
  22. data/lib/cultome_player/player/interactive.rb +67 -11
  23. data/lib/cultome_player/player/interface/basic.rb +13 -9
  24. data/lib/cultome_player/player/interface/extended.rb +26 -12
  25. data/lib/cultome_player/player/interface/helper.rb +73 -9
  26. data/lib/cultome_player/plugins.rb +44 -18
  27. data/lib/cultome_player/plugins/alias.rb +85 -0
  28. data/lib/cultome_player/plugins/gestures.rb +90 -0
  29. data/lib/cultome_player/plugins/help.rb +4 -4
  30. data/lib/cultome_player/plugins/keyboard_special_keys.rb +22 -0
  31. data/lib/cultome_player/plugins/points.rb +51 -0
  32. data/lib/cultome_player/utils.rb +117 -7
  33. data/lib/cultome_player/version.rb +1 -1
  34. data/xbindkeys/xbindkeysrc +12 -0
  35. metadata +37 -89
  36. data/.coveralls.yml +0 -1
  37. data/.gitignore +0 -24
  38. data/.rspec +0 -2
  39. data/.travis.yml +0 -7
  40. data/db/001_create_schema.rb +0 -58
  41. data/spec/config.yml +0 -0
  42. data/spec/cultome_player/command/processor_spec.rb +0 -168
  43. data/spec/cultome_player/command/reader_spec.rb +0 -45
  44. data/spec/cultome_player/cultome_player_spec.rb +0 -17
  45. data/spec/cultome_player/environment_spec.rb +0 -65
  46. data/spec/cultome_player/events_spec.rb +0 -22
  47. data/spec/cultome_player/media_spec.rb +0 -41
  48. data/spec/cultome_player/player/adapter/mpg123_spec.rb +0 -82
  49. data/spec/cultome_player/player/interface/basic_spec.rb +0 -168
  50. data/spec/cultome_player/player/interface/extended/connect_spec.rb +0 -117
  51. data/spec/cultome_player/player/interface/extended/search_spec.rb +0 -90
  52. data/spec/cultome_player/player/interface/extended/show_spec.rb +0 -36
  53. data/spec/cultome_player/player/interface/extended/shuffle_spec.rb +0 -26
  54. data/spec/cultome_player/player/interface/extended_spec.rb +0 -136
  55. data/spec/cultome_player/player/interface/helper_spec.rb +0 -63
  56. data/spec/cultome_player/player/interface_spec.rb +0 -17
  57. data/spec/cultome_player/player/playlist_spec.rb +0 -301
  58. data/spec/cultome_player/plugins/help_spec.rb +0 -21
  59. data/spec/cultome_player/plugins_spec.rb +0 -19
  60. data/spec/cultome_player/utils_spec.rb +0 -15
  61. data/spec/spec_helper.rb +0 -108
  62. data/spec/test/uno/dos/dos.mp3 +0 -0
  63. data/spec/test/uno/dos/tres/tres.mp3 +0 -0
  64. data/spec/test/uno/uno.mp3 +0 -0
  65. data/tasks/console.rake +0 -19
  66. data/tasks/db.rake +0 -19
  67. data/tasks/run.rake +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 520affa57eb4cbb5aee209993047772c18379b0d
4
- data.tar.gz: 2fe8bbee2da06c8515a710edb4666a825e7dd19e
3
+ metadata.gz: 46321051c193edf556318683db732a1d96e3580b
4
+ data.tar.gz: 41926b365494b457983fd4bda0e2766c44834967
5
5
  SHA512:
6
- metadata.gz: c286b696f6881b843c7577bb8451d21a6c8312c61d47e1e6986845b132637c0933311fe9d5ad17c3a3dd39709e7559ce8b36f46a565feaa9c04acf83278fa192
7
- data.tar.gz: 9ac39288b1acea2127f0e7f6d8f19e85f4bf37e5c54912bdb648de9039ab4498fb819628e7703c6b6f97e3d8dd7f4b4a08cae6a3ac73fdae2ef6770ca85c147c
6
+ metadata.gz: 1f324e968d798f079c04a87100774c498558a5f897baeb81a3b754f0f2f881f2ecdc8ec33760c58464748637350e767dcff5b432bf49d51b6aeaec600e49f8d9
7
+ data.tar.gz: 2e8bb3f88b0d007aca2e74435ffd729e48e3794fd46451519eba0cf27655b5b03f59444f7ffb383a7b0146014ff775afa5b75dc8a34ef0fd10d59052027705fb
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/cultome_player.png)](http://badge.fury.io/rb/cultome_player)
2
- [![Build Status](https://travis-ci.org/cultome/cultome_player.svg)](https://travis-ci.org/cultome/cultome_player)
3
- [![Coverage Status](https://coveralls.io/repos/cultome/cultome_player/badge.png)](https://coveralls.io/r/cultome/cultome_player)
2
+ [![Build Status](https://travis-ci.org/cultome/cultome_player.svg?branch=master)](https://travis-ci.org/cultome/cultome_player)
3
+ [![Coverage Status](https://coveralls.io/repos/github/cultome/cultome_player/badge.svg?branch=master)](https://coveralls.io/github/cultome/cultome_player?branch=master)
4
4
 
5
5
  # Cultome Player
6
6
  A handy music library explorer. Is designed to facilitate you to play the music you like in the moment you want.
7
7
 
8
- **"I want to play exactly this music"**
8
+ **"I want to play exactly that song"**
9
9
 
10
10
  The player is designed around this concept, so it has commands to help you find music in your library and play it.
11
11
 
@@ -110,7 +110,7 @@ Some others are not player's objects but act as special functions placeholders.
110
110
  * @genres Referes to the complete list of genres in you *connected* collection.
111
111
  * @recently_added Referes to the list of recently added to the collection's songs.
112
112
  * @recently_played Referes to the list of recently played songs.
113
- * @more_played Referes to the list of songs with more playbacks.
113
+ * @most_played Referes to the list of songs with more playbacks.
114
114
  * @less_played Referes to the list of songs with less playbacks.
115
115
  * @populars Referes to the list of songs with highest puntuations from playback preferences.
116
116
  ```
@@ -169,11 +169,15 @@ Is an absolute path inside the filesystem. As with literals if the path has any
169
169
  ```
170
170
 
171
171
  #### Boolean
172
- Basicly anything that match the next regex is considered a boolean value, so watch out if you try to insert a literal value instead of a boolean.
172
+ Basically anything that match the next regex is considered a boolean value, so watch out if you try to insert a literal value instead of a boolean.
173
173
  ```
174
174
  /^(on|off|yes|false|true|si|no|y|n|s|ok)$/
175
175
  ```
176
176
 
177
+ Note: When the command parser digest your input it try to guess the type of the tokens the best it can. It will match from specific to general, and boolean are more specificthan literals. If you try to write a literal, but yor literal is one of the recognized boolean types, it will detect it as such. This can cause some commands behave in unexpected ways in the worst case, in others may simpy fail.
178
+
179
+ So pay attention if something goes weird when you type "search yes".
180
+
177
181
  #### IP
178
182
  A valid IP4 address.
179
183
 
@@ -183,7 +187,7 @@ A valid IP4 address.
183
187
 
184
188
 
185
189
  ## Commands
186
- The commands are very rustic. Basicly consist in a command name and a list of parameters.
190
+ The commands are very simples, they consist in a command name and a list of parameters.
187
191
 
188
192
  ```ruby
189
193
  <command> [<param>...]
@@ -230,11 +234,20 @@ help <command_name>
230
234
  ```
231
235
 
232
236
  ## Installation
233
- Due I'm not a genius, I rely in an excelent media player as a multimedia backbone. So, unless you're trying to write yor own adapter for other music player, you need to have Mpg123 installed. With linux, is a piece of cake:
237
+ I rely in an excellent media player as a multimedia backbone, so, unless you're trying to write yor own adapter for other music player, you need to have **Mpg123** installed. With linux, is a piece of cake:
234
238
 
235
- For Ubuntu
236
239
  ```
240
+ # Ubuntu
237
241
  sudo apt-get install mpg123
242
+
243
+ # Archlinux (yaourt)
244
+ sudo yaourt mpg123
245
+ ```
246
+
247
+ And to use the ID3 tags I use **taglib** library
248
+ ```
249
+ # Ubuntu
250
+ sudo apt-get install libtag1-dev
238
251
  ```
239
252
 
240
253
  When you finish install this gem:
@@ -248,78 +261,10 @@ connect /home/user/music => main
248
261
  play
249
262
  ```
250
263
 
251
- ## What's new
252
-
253
- **Version 2.0.0**
254
-
255
- You know! I cant remember how many times I have rewrited this player. Mainly I do it because is fun to work in it, but the ugly truth is that I never finish it. However I will try to delivery at least a stable and prolonged api for this version. I'm taking my time and hopefully some day near I can delivery a fully funcional version with the plugins and all the flashing lights. If you wanna try the player while Im building it, try this version, if not stick it to the 1.0.0 (Im using version 1.0.0 while writing this) until I reach the functional point of that version, when that happens I'll post it here.
256
-
257
- UPDATE:
258
-
259
- I'm working again! Some changes ocurred since last update. First I change mi github account for dumb reasons, anyway this is the new old gem and I have this first stable new version. You know, some rought edges but at least is useful. I'll release the gem with another name because the cultome_player namespace is reserved. I let you know which one I pick. Wait the new gem in a couple days.
260
-
261
- **Version 1.0.0**
262
-
263
- I took so long I know, but it was for a good cause. When I realized thanks to [Travis CI](https://travis-ci.org/csoriav/cultome_player) that my code was a little more than difficult to test in more than one environment, considering the weird hybrid that result the JRuby thing, I decided to rewrite all the player, and that was what i been doing since then.
264
-
265
- With the hope to deliver zero-defect, multiple-environment-friendly, less error prone code, a better developer experience and a truly code that could be called gem, I invest a lot of effort writing with a test-first methodology with new version. As you can see my coverage incremented radically.
266
-
267
- As you can imagine, I test a lot, but even with my greattest efforts is possible that some scenarios have gone under the radar. I'm also conscient that this version still has some jagged edges, mostly of then I have identified but, by the nature of this change and the time it took, i decide to release this stable version and polish all the other things in the next release.
268
-
269
- So, whats new with this release? Well at first sight you will feel the speed in the starting, also will note the memory consumption is now less than half than before. I also remove dependencies but over all now the player is **PURE RUBY**... well! you still need to have java installed because the music player is the same, but now run in a separate process and the communication between ruby and java is with sockets. This allows to use the gem even without a music player or connect a nother player, lets say mplayer, with just overwriting a couple methods =D
270
-
271
- I remove the share funcitonality in this version, but it will come back in esteroids in future releases.
272
-
273
- Whats next? Musicbrainz integration, I need to tags correctly all the songs if I want to go further. So, see you next version!
274
-
275
- **Version 0.4.0**
276
-
277
- * Now you database and your config file are inside you user directory (~/.cultome), that mean every new version dont require re-connect you music or make your aliases again.
278
- * Scrobbler? of course! why not? but please run **'configure_lastfm begin'** before use it.
279
- * Better environment startup check.
280
-
281
- **Version 0.3.0**
282
-
283
- * Colors!!! Yeah! a color schema that you can customize if you dont like mine.
284
- * Some ASCII progress bars to let you know the player is not stuck!
285
- * Improvement in the 'help <command>' command, to, hopefully help you you surf in the player.
286
- * Add but not yet fully tested the *share* command to share music between two machines.
287
- * Some minor bugs fixed.
288
- * Specs up to date! YEAH!
289
-
290
- **Version 0.2.0**
291
-
292
- * The code were reorganized to be more API-oriented, even when this was not the mainly intention of this project, but can be uselful for others to use it this way.
293
- * The some commands were extracted from the core, like help and kill.
294
- * The command 'copy <object> <destiny_path>' were added to copy all the songs in the objet to a directory in the filesystem.
295
- * The option 'search @\<artist|album\>' was implemented to facilitate the __'that album rocks! lets hear it!'__.
296
- * The player now emit exception-thrown events, a general exception and a player's exception.
297
- * The aliases/shortcuts/macros plugin is in place. With this you can translate user input into commands, for example type 'sa' and the players tranform it to 'search @artist'.
298
- * Changes in plugin structure. Not the final version but a step ahead for building a better plugin model.
299
- * Some minor bugs fixes, like the db hanging or the lost in focus when search is empty.
300
-
301
- ## TODO
302
-
303
- * Connect with musicbrainz to tag correctly and beatifuly my music, this also surge as Last.fm is very picky with the information you submit with your scrobbles.
304
- * Add tags to the songs, for example 'party' or 'sadness'.
305
- * A friend of mine give me an idea, when you are in a place where many people hear the same music, you should be able to decide what to play, as everyone else. So I will try an implementation of this idea, maybe a slave-masters model.
306
- * Support for Windows. Not my priority but would be nice my wife to use it.
307
- * Add gestures to the detector and start making appropiated suggestions for them.
308
- * Refine the taste analizer, which is the component that give preference points to songs.
309
- * Change the underlying in-file database for a real one, thinking on mongo or mysql.
310
-
311
264
  ## Contributing
312
265
 
313
- 1. Fork it
266
+ 1. Fork it
314
267
  2. Create your feature branch (`git checkout -b my-new-feature`)
315
- 3. Commit your changes (`git commit -am 'Add some feature'`)
268
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
316
269
  4. Push to the branch (`git push origin my-new-feature`)
317
- 5. Create new Pull Request
318
-
319
- ## Additional Information
320
-
321
- #### jlGui BasicPlayer
322
- This component is what I use to play music and is included within the libraries of this project, dependencies included of course.
323
-
324
- [jlGui](http://www.javazoom.net/jlgui/developerguide.html)
325
-
270
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,8 +1,42 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'cultome_player'
2
3
 
3
- $LOAD_PATH.unshift(File.join(File.dirname(File.expand_path(__FILE__)), 'lib'))
4
+ desc "Execute the player in interactive mode in user env"
5
+ task :run => :environment do
6
+ player = CultomePlayer.get_player(current_env)
7
+ player.begin_session
8
+ end
9
+
10
+ desc "Create database schema"
11
+ task :reset_db => :environment do
12
+ include CultomePlayer::Utils
13
+ recreate_db_schema
14
+ end
15
+
16
+ desc "Start a interactive session in the player"
17
+ task :console => :environment do
18
+ require 'irb'
19
+ require 'irb/completion'
20
+
21
+ p = CultomePlayer.get_player(current_env)
22
+
23
+ ActiveRecord::Base.establish_connection({
24
+ adapter: db_adapter,
25
+ database: db_file
26
+ })
27
+ ActiveRecord::Base.logger = Logger.new(File.open(db_log_file, 'a'))
28
+
29
+ include CultomePlayer
30
+ include CultomePlayer::Environment
31
+
32
+ ARGV.clear
33
+ IRB.start
34
+ end
35
+
36
+ task :environment do |t, args|
37
+ include CultomePlayer::Environment
4
38
 
5
- dirname = File.join(File.dirname(File.expand_path(__FILE__)), "tasks")
6
- Dir.entries(dirname).each do |task|
7
- import "#{dirname}/#{task}" if task.end_with?(".rake")
39
+ env = ENV["ENV"] || :user
40
+ prepare_environment(env)
41
+ puts "Using #{env} environment."
8
42
  end
@@ -7,19 +7,24 @@ require 'cultome_player'
7
7
  options = {
8
8
  interactive: false,
9
9
  environment: :user,
10
+ signal: false,
10
11
  }
11
12
 
12
13
  parser = OptionParser.new do |opts|
13
14
  opts.banner = "Usage: cultome_player [options] [file1, file2, ...]"
14
15
 
15
- opts.on('-i', '--interactive', 'Starts the player in interactive mode') do
16
+ opts.on('-i', '--interactive', 'Starts the player in interactive mode. [false]') do
16
17
  options[:interactive] = true
17
18
  end
18
19
 
19
- opts.on('-e', '--env ENV', 'Starts the player in interactive mode') do |env|
20
+ opts.on('-e', '--env ENV', 'Select settings from environment. [user]') do |env|
20
21
  options[:environment] = env.to_sym
21
22
  end
22
23
 
24
+ opts.on('-s', '--signal SIG', 'Send a command to all the command pipes.') do |sig|
25
+ options[:signal] = sig.gsub(/"/, "")
26
+ end
27
+
23
28
  opts.on('--version', "Shows version") do
24
29
  puts CultomePlayer::VERSION
25
30
  exit
@@ -32,8 +37,15 @@ ARGV << "--help" if ARGV.empty?
32
37
  # parseamos las opciones
33
38
  parser.parse!(ARGV)
34
39
 
35
- player = CultomePlayer.get_player(options[:environment])
36
-
37
40
  if options[:interactive]
41
+ player = CultomePlayer.get_player(options[:environment])
38
42
  player.begin_session
43
+ elsif options[:signal]
44
+ begin
45
+ include CultomePlayer::Environment
46
+ config = load_environment_properties(options[:environment])
47
+ puts "[*] Writing to signal '#{options[:signal]}' to pipe '#{config["command_pipe"]}'"
48
+ open(config["command_pipe"], File::WRONLY | File::NONBLOCK | File::SYNC){|out| out.puts options[:signal]}
49
+ rescue Errno::ENXIO, Errno::ENOENT => e
50
+ end
39
51
  end
@@ -4,6 +4,7 @@ user:
4
4
  db_log_file: ~/.cultome/db.log
5
5
  file_types: mp3
6
6
  mplayer_pipe: ~/.cultome/mpctr
7
+ command_pipe: ~/.cultome/cmdctr
7
8
  config_file: ~/.cultome/config.yml
8
9
  memory:
9
10
  db_adapter: sqlite3
@@ -11,6 +12,7 @@ memory:
11
12
  db_log_file: /tmp/db.log
12
13
  file_types: mp3
13
14
  mplayer_pipe: /tmp/mpctr
15
+ command_pipe: /tmp/cmdctr
14
16
  config_file: /tmp/config.yml
15
17
  rspec:
16
18
  db_adapter: sqlite3
@@ -18,6 +20,7 @@ rspec:
18
20
  db_log_file: spec/db.log
19
21
  file_types: mp3
20
22
  mplayer_pipe: spec/mpctr
23
+ command_pipe: spec/cmdctr
21
24
  config_file: spec/config.yml
22
25
  test:
23
26
  db_adapter: sqlite3
@@ -25,4 +28,5 @@ test:
25
28
  db_log_file: ~/tmp/db.log
26
29
  file_types: mp3
27
30
  mplayer_pipe: ~/tmp/mpctr
31
+ command_pipe: ~/tmp/cmdctr
28
32
  config_file: ~/tmp/config.yml
@@ -2,6 +2,13 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'cultome_player/version'
5
+ # select the faile that goes inside the gem
6
+ git_index = `git ls-files`.split("\n")
7
+ gitignored = `cat .gitignore`.split("\n")
8
+ excluded = `cat .excluded`.split("\n")
9
+
10
+ files = git_index.select{|filepath| !gitignored.include?(filepath) }
11
+ .select{|filepath| excluded.none?{|excl_regex| filepath =~ /#{excl_regex}/ }}
5
12
 
6
13
  Gem::Specification.new do |gem|
7
14
  gem.name = "cultome_player"
@@ -13,7 +20,7 @@ Gem::Specification.new do |gem|
13
20
  gem.homepage = "https://github.com/cultome/cultome_player"
14
21
  gem.license = "MIT"
15
22
 
16
- gem.files = `git ls-files`.split($/)
23
+ gem.files = files
17
24
  gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
25
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
26
  gem.require_paths = ["lib"]
@@ -25,21 +25,45 @@ module CultomePlayer
25
25
  # @param user_input [String] The user input.
26
26
  # @return [Response] Response object with information about command execution.
27
27
  def execute(user_input)
28
- cmd = parse user_input
29
- # revisamos si es un built in command o un plugin
30
- action = cmd.action
31
- plugin_action = "command_#{cmd.action}".to_sym
32
- action = plugin_action if respond_to?(plugin_action)
33
-
34
- raise 'invalid command:action unknown' unless respond_to?(action)
35
- with_connection do
36
- begin
37
- send(action, cmd)
38
- rescue Exception => e
39
- s = e.message.split(":")
40
- failure(message: s[0], details: s[1])
28
+ cmds = parse user_input
29
+
30
+ seq_success = true # bandera de exito, si un comando de la cadena falla, los siguientes se abortan
31
+ response_seq = cmds.collect do |cmd|
32
+ if seq_success
33
+ # revisamos si es un built in command o un plugin
34
+ action = cmd.action
35
+ plugin_action = "command_#{cmd.action}".to_sym
36
+ action = plugin_action if plugins_respond_to?(cmd.action)
37
+
38
+ raise 'invalid command:action unknown' unless respond_to?(action)
39
+ with_connection do
40
+ begin
41
+ emit_event(:before_command, cmd)
42
+ emit_event("before_command_#{action}".to_sym, cmd) if cmd.history?
43
+ r = send(action, cmd)
44
+ emit_event("after_command_#{action}".to_sym, cmd, r) if cmd.history?
45
+ emit_event(:after_command, cmd, r)
46
+
47
+ seq_success = false unless r.success?
48
+ r # return response
49
+ rescue Exception => e
50
+ emit_event(:execute_exception, cmd, e)
51
+
52
+ if current_env == :test || current_env == :rspec
53
+ display c3("#{e.message}")
54
+ e.backtrace.each{|b| display c3(b) }
55
+ end
56
+
57
+ seq_success = false
58
+ s = e.message.split(":")
59
+ failure(message: s[0], details: s[1])
60
+ end
61
+ end
62
+ else # seq_success == false
63
+ nil
41
64
  end
42
65
  end
66
+ return response_seq.compact # eliminamos los que no corrieron
43
67
  end
44
68
 
45
69
  # Creates a generic response
@@ -74,18 +98,20 @@ module CultomePlayer
74
98
 
75
99
  def initialize(env)
76
100
  prepare_environment(env)
101
+ ensure_db_schema
77
102
  playlists.register(:current)
78
103
  playlists.register(:history)
79
104
  playlists.register(:queue)
80
105
  playlists.register(:focus)
81
106
  playlists.register(:search)
82
-
83
- register_listener(:playback_finish, self)
84
- end
85
107
 
86
- def on_playback_finish
87
- r = execute("next no_history")
88
- display_over("#{r.message}\n#{PROMPT}")
108
+ register_listener(:playback_finish) do |song|
109
+ r = execute("next").first
110
+ display_over("#{r.message}\n#{c5(PROMPT)}")
111
+ end
112
+
113
+ init_plugins
114
+ ObjectSpace.define_finalizer(self, proc{ clean_plugins })
89
115
  end
90
116
  end
91
117
 
@@ -1,10 +1,10 @@
1
1
  module CultomePlayer::Command
2
2
  module Language
3
3
 
4
- # Define the sintaxis of the player language.
4
+ # Define the sintax of the player language.
5
5
  #
6
6
  # @return [Hash] With the keys :command, :parameters, :actions, :param
7
- def sintaxis
7
+ def sintax
8
8
  # <command> : <action> | <action> <parameters>
9
9
  # <action> : literal
10
10
  # <parameters> : <param> | <param> <parameters>
@@ -53,9 +53,8 @@ module CultomePlayer::Command
53
53
  {type: :criteria, identity: /^([\w]+):([\d\w\s]+)$/, captures: 2, labels: [:criteria, :value]},
54
54
  {type: :boolean, identity: /^(on|off|yes|false|true|si|no|y|n|s|ok)$/},
55
55
  {type: :ip, identity: /^([\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})$/},
56
- {type: :literal, identity: /^([\w\d\s]+)$/},
56
+ {type: :literal, identity: /^['"]?([\w\d\s%]+)['"]?$/}, # add % for the alias parameters placeholders
57
57
  ]
58
58
  end
59
-
60
59
  end
61
60
  end
@@ -6,9 +6,11 @@ module CultomePlayer::Command
6
6
  # @param user_input [String] The user input to be parsed.
7
7
  # @return [Command] The parsed command.
8
8
  def parse(user_input)
9
- tokens = identify_tokens(get_tokens(user_input))
10
- validate_command(:command, tokens)
11
- return CultomePlayer::Objects::Command.new(tokens.shift, tokens)
9
+ return user_input.split("&&").collect do |usr_in|
10
+ tokens = identify_tokens(get_tokens(usr_in.strip))
11
+ validate_command(:command, tokens)
12
+ CultomePlayer::Objects::Command.new(tokens.shift, tokens)
13
+ end
12
14
  end
13
15
 
14
16
  # Split the user input into tokens.
@@ -68,7 +70,7 @@ module CultomePlayer::Command
68
70
  valid_format = semantics[cmd]
69
71
  if valid_format.nil?
70
72
  if plugins_respond_to?(cmd)
71
- valid_format = plugin_command_sintaxis(cmd)
73
+ valid_format = plugin_command_sintax(cmd)
72
74
  else
73
75
  raise 'invalid command:invalid action'
74
76
  end
@@ -131,10 +133,10 @@ module CultomePlayer::Command
131
133
 
132
134
  def guess_command_format(type, tokens)
133
135
  # buscamos el formato que tenga mas matches con los parametros
134
- format = sintaxis[type].find do |stxs_elem| # ["action", "action parameters"]
136
+ format = sintax[type].find do |stxs_elem| # ["action", "action parameters"]
135
137
  if stxs_elem.is_a?(String)
136
138
  # checamos si el numero de token en el comando corresponde
137
- # con el numer de tokens en la sintaxis
139
+ # con el numer de tokens en la sintax
138
140
  stxs_elem.split.size >= tokens.size # ej. "play 1 2" === "action paramters"
139
141
  elsif stxs_elem.is_a?(Symbol)
140
142
  if tokens.is_a?(Hash)
@@ -150,7 +152,7 @@ module CultomePlayer::Command
150
152
  end
151
153
 
152
154
  if format.nil?
153
- max = sintaxis[type].max{|tk| tk.class == String ? tk.split.size: 0}
155
+ max = sintax[type].max{|tk| tk.class == String ? tk.split.size: 0}
154
156
  if max.respond_to?(:split) && tokens.size > max.split.size
155
157
  format = max
156
158
  else