Class: RunningTrack::TrackCollection
- Inherits:
-
Object
- Object
- RunningTrack::TrackCollection
show all
- Defined in:
- lib/mosTrack/track_collection.rb
Defined Under Namespace
Classes: RunningTrackLoadLocalDataError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data = Array.new) ⇒ TrackCollection
Returns a new instance of TrackCollection.
Instance Attribute Details
#tracks ⇒ Object
Returns the value of attribute tracks.
8
9
10
|
# File 'lib/mosTrack/track_collection.rb', line 8
def tracks
@tracks
end
|
Instance Method Details
#find(key, value) ⇒ Object
30
31
32
33
34
|
# File 'lib/mosTrack/track_collection.rb', line 30
def find key, value
@tracks.select do |e|
e.to_hash[key] == value
end
end
|
#load! ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/mosTrack/track_collection.rb', line 40
def load!
local_data = YAML.load_file('./data/file.yml')
raise RunningTrackLoadLocalDataError, "Локальных данных нет!" if !local_data
@tracks = YAML.load_file('./data/file.yml').map do |e|
Track.new(e)
end
end
|
#random(count = 1) ⇒ Object
26
27
28
|
# File 'lib/mosTrack/track_collection.rb', line 26
def random count = 1
@tracks.shuffle.slice(0..count-1)
end
|
#save! ⇒ Object
36
37
38
|
# File 'lib/mosTrack/track_collection.rb', line 36
def save!
File.open('./data/file.yml', 'w') {|f| f.write self.to_hash.to_yaml }
end
|
#to_hash ⇒ Object
48
49
50
51
52
|
# File 'lib/mosTrack/track_collection.rb', line 48
def to_hash
hash = @tracks.map do |e|
e.to_hash
end
end
|