class MusicBox::Group::Item
Attributes
dir[RW]
id[RW]
Public Class Methods
load(dir, params={})
click to toggle source
# File lib/musicbox/group.rb, line 131 def self.load(dir, params={}) dir = Path.new(dir) info_file = dir / Group::InfoFileName raise Error, "Info file does not exist: #{info_file}" unless info_file.exist? new(JSON.load(info_file.read).merge(dir: dir).merge(params)) end
new(params={})
click to toggle source
# File lib/musicbox/group.rb, line 138 def initialize(params={}) params.each { |k, v| send("#{k}=", v) } end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/musicbox/group.rb, line 161 def <=>(other) @id <=> other.id end
fields(keys)
click to toggle source
# File lib/musicbox/group.rb, line 157 def fields(keys) keys.map { |k| send(k) } end
info_file()
click to toggle source
# File lib/musicbox/group.rb, line 142 def info_file @dir / Group::InfoFileName end
save()
click to toggle source
# File lib/musicbox/group.rb, line 146 def save ;;warn "* saving item to #{@dir}" raise Error, "dir not defined" unless @dir @dir.mkpath unless @dir.exist? info_file.write(JSON.pretty_generate(serialize)) end
serialize(args={})
click to toggle source
# File lib/musicbox/group.rb, line 153 def serialize(args={}) { id: @id }.merge(args).compact end