Class: MusicBox::Group::Item
- Inherits:
-
Object
- Object
- MusicBox::Group::Item
show all
- Defined in:
- lib/musicbox/group.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(params = {}) ⇒ Item
Returns a new instance of Item.
138
139
140
|
# File 'lib/musicbox/group.rb', line 138
def initialize(params={})
params.each { |k, v| send("#{k}=", v) }
end
|
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
129
130
131
|
# File 'lib/musicbox/group.rb', line 129
def dir
@dir
end
|
#id ⇒ Object
Returns the value of attribute id.
128
129
130
|
# File 'lib/musicbox/group.rb', line 128
def id
@id
end
|
Class Method Details
.load(dir, params = {}) ⇒ Object
131
132
133
134
135
136
|
# 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
|
Instance Method Details
#<=>(other) ⇒ Object
161
162
163
|
# File 'lib/musicbox/group.rb', line 161
def <=>(other)
@id <=> other.id
end
|
#fields(keys) ⇒ Object
157
158
159
|
# File 'lib/musicbox/group.rb', line 157
def fields(keys)
keys.map { |k| send(k) }
end
|
#info_file ⇒ Object
142
143
144
|
# File 'lib/musicbox/group.rb', line 142
def info_file
@dir / Group::InfoFileName
end
|
#save ⇒ Object
146
147
148
149
150
151
|
# 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 = {}) ⇒ Object
153
154
155
|
# File 'lib/musicbox/group.rb', line 153
def serialize(args={})
{ id: @id }.merge(args).compact
end
|