class RunningTrack::TrackCollection

Attributes

tracks[R]

Public Class Methods

new(data = Array.new) click to toggle source
# File lib/mosTrack/track_collection.rb, line 13
def initialize data = Array.new
        @tracks = data.map do |e|
                Track.new({
                        Track::TRACK_DISTRICT_KEY => e["District"],
                        Track::TRACK_ADDRESS_KEY => e["Address"],
                        Track::TRACK_PHONE_KEY => e["HelpPhone"],
                        Track::TRACK_HAS_WIFI_KEY => e["ObjectHasWifi"]
                })
        end
        # p find(Track::TRACK_HAS_WIFI_KEY, "нет")
        @tracks = random(@tracks.count)
end

Public Instance Methods

find(key, value) click to toggle source
# File lib/mosTrack/track_collection.rb, line 30
def find key, value
        @tracks.select do |e|
                e.to_hash[key] == value
        end
end
load!() click to toggle source
# 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) click to toggle source
# File lib/mosTrack/track_collection.rb, line 26
def random count = 1
        @tracks.shuffle.slice(0..count-1)
end
save!() click to toggle source
# 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() click to toggle source
# File lib/mosTrack/track_collection.rb, line 48
def to_hash
        hash = @tracks.map do |e|   
                e.to_hash
        end
end