Class: Aniview::Interface::Schedule
- Inherits:
-
Bridge
- Object
- Bridge
- Aniview::Interface::Schedule
show all
- Includes:
- Util, Observable
- Defined in:
- lib/aniview/interface/schedule/schedule.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Util
decode_object, encode_object, error_message, format_duration, format_progress, format_size, mounted_filesystem?, parse_format, readline
Methods inherited from Bridge
#make_hash
Constructor Details
#initialize(pref) ⇒ Schedule
Returns a new instance of Schedule.
17
18
19
20
|
# File 'lib/aniview/interface/schedule/schedule.rb', line 17
def initialize pref
@pref = pref
load
end
|
Instance Attribute Details
#schedule ⇒ Object
Returns the value of attribute schedule.
15
16
17
|
# File 'lib/aniview/interface/schedule/schedule.rb', line 15
def schedule
@schedule
end
|
Instance Method Details
#addItem(item) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/aniview/interface/schedule/schedule.rb', line 54
def addItem item
@schedule.delete_at 0 if @schedule[0].attributes["t"] == "no schedule"
new_item = ScheduleItem.new(item, @pref.get("airing_dir"))
FileUtils.mkdir_p @pref.parseDir new_item.attributes["p"]
@schedule << new_item
save
end
|
#editItem(loc, val) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/aniview/interface/schedule/schedule.rb', line 66
def editItem loc, val
old_dir = @pref.parseDir @schedule[loc].attributes["p"]
@schedule[loc].setTitle val
new_dir = @pref.parseDir @schedule[loc].attributes["p"]
FileUtils.mv old_dir, new_dir unless old_dir.downcase == new_dir.downcase
save
end
|
#empty? ⇒ Boolean
22
23
24
25
26
27
|
# File 'lib/aniview/interface/schedule/schedule.rb', line 22
def empty?
if @schedule == nil or @schedule.length == 0
@schedule = [ScheduleItem.new("no schedule", "")]
save
end
end
|
#getAllCereal ⇒ Object
34
35
36
37
38
|
# File 'lib/aniview/interface/schedule/schedule.rb', line 34
def getAllCereal
r=""
getAll.each { |si| r+=si.cereal }
r
end
|
#items ⇒ Object
29
30
31
32
|
# File 'lib/aniview/interface/schedule/schedule.rb', line 29
def items
empty?
@schedule.map{ |t| [t,t] }.to_h
end
|
#load ⇒ Object
87
88
89
90
91
92
93
94
95
|
# File 'lib/aniview/interface/schedule/schedule.rb', line 87
def load
raw = @pref.get "schedule"
if not raw == nil and raw.class == String
@schedule = Util.decode_object raw
else
empty?
end
end
|
#mergeItems(_items) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/aniview/interface/schedule/schedule.rb', line 40
def mergeItems _items
_items.each { |item|
@schedule.each { |schedule_item|
if item.id == schedule_item.id
m = [schedule_item.attributes["m"], item.attributes["m"]]
if m[0] != m[1]
schedule_item.setmatched m[1]
end
end
}
}
save
end
|
#removeItem(loc) ⇒ Object
76
77
78
79
|
# File 'lib/aniview/interface/schedule/schedule.rb', line 76
def removeItem loc
@schedule.delete_at loc
save
end
|
#save ⇒ Object
81
82
83
84
85
|
# File 'lib/aniview/interface/schedule/schedule.rb', line 81
def save
@pref.set "schedule", (Util.encode_object @schedule)
changed
notify_observers
end
|