musicrb 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99779b60ed03d9d853e545a43b2de8ef964914b7ca74b7ec75c587ad0ba52648
4
- data.tar.gz: 67c33efb466ab01e6f3b71c0fbf720ccb5380fbcb24961c945fa080bbfceda23
3
+ metadata.gz: f6a1b451c196d0b2ed8ee0a747521fd8ab33e67a4a790cdc88ffc2b97b58f333
4
+ data.tar.gz: d770c267aa933d583487b27444cfdb242ba3c26d509c4d7af4e5eaa65a2152fb
5
5
  SHA512:
6
- metadata.gz: d7b6558f89696b49a1881e05c780003f781fe82d10bbf336eeaceee99f8200bb1740538ef03f8669653b67835d8157aed235ca1a1f78d66b4296e88bfdd8a8d7
7
- data.tar.gz: ecf0c6f52a1a87fd43afc0ffe9c56974c11128cc62d10c1380502c758b98a978f5d4f189f5866799ae2ae3a35774eb17e4f45fd0d460feeb8e4c013fe4951144
6
+ metadata.gz: 58ceacdffbd18c92a243681d4e62d53cbbcfb155c8ec333f63351479eb3670fd31812f4cb89a58157c9219217afa31ad6c8aa5d18f03cf764cc8c0b4f7395f6d
7
+ data.tar.gz: d22b0e4ef6e4d4aeaf595a4ea3b4f9aa7607c08ef612589ce73277199ddb75fd24205a3341d0a66c48d97d430165d499be6ed79ea3c89cbcb466880b266da0f1
Binary file
data/lib/musicrb.rb CHANGED
@@ -1,2 +1,9 @@
1
- require 'musicrb/musicrb'
1
+ # frozen_string_literal: true
2
+
3
+ class Music
4
+ VERSION = '1.0.0'
5
+ end
2
6
 
7
+ require 'play_list'
8
+
9
+ require 'musicrb/musicrb'
data/lib/play_list.rb ADDED
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Music
4
+ # Media is a class used to reference any music with any format
5
+ class Media
6
+ attr_reader :title, :artist, :album, :genre
7
+
8
+ def to_s
9
+ "#{title} | #{artist} | #{album} | #{genre}"
10
+ end
11
+ end
12
+
13
+ # PlayList is a class used to create and play a list of musics
14
+ class PlayList
15
+ attr_reader :name, :list
16
+
17
+ def initialize(name)
18
+ @name = name
19
+ @list = []
20
+ @current_media = 0
21
+ @playing = false
22
+ end
23
+
24
+ def to_s
25
+ "Playlist: #{name}\n#{list_to_s}"
26
+ end
27
+
28
+ def load(file_path)
29
+ @list << Media.load(file_path)
30
+ end
31
+
32
+ def play
33
+ stop_others_others_play_lists
34
+ @playing = true
35
+
36
+ @current_media = 0 if @current_media >= @list.length
37
+ media = @list[@current_media]
38
+
39
+ return if media == nil
40
+
41
+ intern_play(media)
42
+
43
+ media
44
+ end
45
+
46
+ def prev
47
+ @current_media = (@current_media - 1) % list.length
48
+ play
49
+ end
50
+
51
+ def next
52
+ @current_media = (@current_media + 1) % list.length
53
+ play
54
+ end
55
+
56
+ private
57
+
58
+ def list_to_s
59
+ @list.map(&:to_s).each_with_index.reduce("") do |str, (media_str, idx)|
60
+ show_icon = (@playing && idx == @current_media)
61
+ track_str = "#{idx + 1} - #{media_str}\n"
62
+
63
+ str += show_icon ? "► #{track_str}" : track_str
64
+ end
65
+ end
66
+
67
+ def stop_others_others_play_lists
68
+ ObjectSpace.each_object(Music::PlayList) { |play_list| play_list.instance_variable_set("@playing", false) }
69
+ end
70
+ end
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musicrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - juneira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-05 00:00:00.000000000 Z
11
+ date: 2023-04-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A player for music
14
14
  email: marcelo.jr63@gmail.com
@@ -20,6 +20,7 @@ files:
20
20
  - ext/musicrb/extconf.rb
21
21
  - lib/musicrb.rb
22
22
  - lib/musicrb/musicrb.so
23
+ - lib/play_list.rb
23
24
  homepage: https://github.com/juneira/musicrb
24
25
  licenses:
25
26
  - MIT