class Dirble::Song
Attributes
id[RW]
image_url[RW]
name[RW]
played_on[RW]
raw[RW]
spotify_url[RW]
title[RW]
Public Class Methods
factory(list_of_songs)
click to toggle source
# File lib/dirble/song.rb, line 38 def factory(list_of_songs) list_of_songs.map do |song| build_song(song) end end
Private Class Methods
build_song(song_params)
click to toggle source
# File lib/dirble/song.rb, line 46 def build_song(song_params) new_song = self.new new_song.instance_eval do self.raw = song_params self.id = fetch_id self.image_url = fetch_image_url self.name = fetch_name self.title = fetch_title self.spotify_url = fetch_spotify_url self.played_on = fetch_played_on end new_song end
Public Instance Methods
date()
click to toggle source
# File lib/dirble/song.rb, line 29 def date raw.fetch('date', {}) end
fetch_id()
click to toggle source
# File lib/dirble/song.rb, line 9 def fetch_id raw.fetch('_id', {}).fetch('$id', nil) end
fetch_image_url()
click to toggle source
# File lib/dirble/song.rb, line 13 def fetch_image_url info.fetch('image', nil) end
fetch_name()
click to toggle source
# File lib/dirble/song.rb, line 17 def fetch_name raw.fetch('name', nil) end
fetch_played_on()
click to toggle source
# File lib/dirble/song.rb, line 33 def fetch_played_on Time.at(date['sec']) end
fetch_spotify_url()
click to toggle source
# File lib/dirble/song.rb, line 25 def fetch_spotify_url info.fetch('urls', {}).fetch('spotify', nil) end
fetch_title()
click to toggle source
# File lib/dirble/song.rb, line 21 def fetch_title raw.fetch('title', nil) end
info()
click to toggle source
# File lib/dirble/song.rb, line 5 def info raw.fetch('info') || {} end