Class: Wavesync::Set
- Inherits:
-
Object
- Object
- Wavesync::Set
- Defined in:
- lib/wavesync/set.rb
Constant Summary collapse
- SETS_FOLDER =
'.sets'
Instance Attribute Summary collapse
-
#library_path ⇒ Object
readonly
: String.
-
#name ⇒ Object
readonly
: String.
-
#tracks ⇒ Object
readonly
: Array.
Class Method Summary collapse
-
.all(library_path) ⇒ Object
: (String library_path) -> Array.
-
.exists?(library_path, name) ⇒ Boolean
: (String library_path, String name) -> bool.
-
.load(library_path, name) ⇒ Object
: (String library_path, String name) -> Set.
-
.set_path(library_path, name) ⇒ Object
: (String library_path, String name) -> String.
-
.sets_path(library_path) ⇒ Object
: (String library_path) -> String.
Instance Method Summary collapse
-
#add_track(path) ⇒ Object
: (String path) -> void.
-
#initialize(library_path, name, tracks = []) ⇒ Set
constructor
: (String library_path, String name, ?Array tracks) -> void.
-
#move_down(index) ⇒ Object
: (Integer index) -> void.
-
#move_up(index) ⇒ Object
: (Integer index) -> void.
-
#remove_track(index) ⇒ Object
: (Integer index) -> String?.
-
#save ⇒ Object
: () -> void.
Constructor Details
Instance Attribute Details
#library_path ⇒ Object (readonly)
: String
13 14 15 |
# File 'lib/wavesync/set.rb', line 13 def library_path @library_path end |
#name ⇒ Object (readonly)
: String
11 12 13 |
# File 'lib/wavesync/set.rb', line 11 def name @name end |
#tracks ⇒ Object (readonly)
: Array
12 13 14 |
# File 'lib/wavesync/set.rb', line 12 def tracks @tracks end |
Class Method Details
.all(library_path) ⇒ Object
: (String library_path) -> Array
32 33 34 35 36 37 38 39 40 |
# File 'lib/wavesync/set.rb', line 32 def self.all(library_path) path = sets_path(library_path) return [] unless Dir.exist?(path) Dir.glob(File.join(path, '*.yml')).map do |file| data = YAML.load_file(file) new(library_path, data['name'], (library_path, data['tracks'])) end.sort_by(&:name) end |
.exists?(library_path, name) ⇒ Boolean
: (String library_path, String name) -> bool
43 44 45 |
# File 'lib/wavesync/set.rb', line 43 def self.exists?(library_path, name) File.exist?(set_path(library_path, name)) end |
.load(library_path, name) ⇒ Object
: (String library_path, String name) -> Set
26 27 28 29 |
# File 'lib/wavesync/set.rb', line 26 def self.load(library_path, name) data = YAML.load_file(set_path(library_path, name)) new(library_path, data['name'], (library_path, data['tracks'])) end |
.set_path(library_path, name) ⇒ Object
: (String library_path, String name) -> String
21 22 23 |
# File 'lib/wavesync/set.rb', line 21 def self.set_path(library_path, name) File.join(sets_path(library_path), "#{name}.yml") end |
.sets_path(library_path) ⇒ Object
: (String library_path) -> String
16 17 18 |
# File 'lib/wavesync/set.rb', line 16 def self.sets_path(library_path) File.join(library_path, SETS_FOLDER) end |
Instance Method Details
#add_track(path) ⇒ Object
: (String path) -> void
55 56 57 |
# File 'lib/wavesync/set.rb', line 55 def add_track(path) @tracks << path end |
#move_down(index) ⇒ Object
: (Integer index) -> void
72 73 74 75 76 |
# File 'lib/wavesync/set.rb', line 72 def move_down(index) return if index >= @tracks.size - 1 @tracks[index], @tracks[index + 1] = @tracks[index + 1], @tracks[index] end |
#move_up(index) ⇒ Object
: (Integer index) -> void
65 66 67 68 69 |
# File 'lib/wavesync/set.rb', line 65 def move_up(index) return if index <= 0 @tracks[index], @tracks[index - 1] = @tracks[index - 1], @tracks[index] end |
#remove_track(index) ⇒ Object
: (Integer index) -> String?
60 61 62 |
# File 'lib/wavesync/set.rb', line 60 def remove_track(index) @tracks.delete_at(index) end |
#save ⇒ Object
: () -> void
79 80 81 82 |
# File 'lib/wavesync/set.rb', line 79 def save FileUtils.mkdir_p(self.class.sets_path(@library_path)) File.write(self.class.set_path(@library_path, @name), to_yaml) end |