Skip to content

Instantly share code, notes, and snippets.

@rjhornsby
Last active August 29, 2015 14:23
Show Gist options
  • Save rjhornsby/6db2760db605bea6f865 to your computer and use it in GitHub Desktop.
Save rjhornsby/6db2760db605bea6f865 to your computer and use it in GitHub Desktop.
Ruby Song class
class Song
# TODO: enforce limits on the input
attr_accessor :title
attr_accessor :artist
attr_accessor :album
attr_accessor :remarks
attr_accessor :url
attr_accessor :error
def initialize(
title = nil,
artist = nil,
album = nil,
remarks = nil,
url = nil
)
@title = title
@artist = artist
@album = album
@remarks = remarks
@url = url
end
def to_json(*a)
puts "Making a json string from a #{self.class.name}"
{
'json_class' => self.class.name,
'data' => {
:title => title,
:artist => artist,
:album => album,
:remarks => remarks,
:url => url
}
}.to_json(*a)
end
def self.json_create(*o)
puts "Making a #{self.class.name}"
pp o
new(
o[0]['data']['title'],
o[0]['data']['artist'],
o[0]['data']['album'],
o[0]['data']['remarks'],
o[0]['data']['url']
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment