Class: Aniview::View::AioMenu

Inherits:
Menu
  • Object
show all
Includes:
Util
Defined in:
lib/aniview/view/aiomenu.rb

Instance Attribute Summary

Attributes inherited from Menu

#attributes, #format

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 Menu

#adjustView, #auto_update, #change_screen_size, #color, #control, #draw, #expand, #fixCursor, #getLen, #initialize, #interface, #moveCursor, #pause, #refresh, #refreshFormats, #resolve_selected, #rfunc=, #unpause, #updated!, #updated?

Constructor Details

This class inherits a constructor from Aniview::View::Menu

Instance Method Details

#customControl(key, sel) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/aniview/view/aiomenu.rb', line 36

def customControl(key, sel)
  return if @items == {}
  path = @items.values[sel["out"]][sel["in"]].path

  empty = path == "empty"
    
  if key == @pref.get("keybindings")["menu_nav_expand"]
    expand(sel["out"])
  elsif key == "r"
    refresh
  elsif key == "enter" and not empty

    if sel["in_expanded"]  
      @interface.watch(@items.values[sel["out"]][sel["in"]])
      @interface.logWatched(path)
    else
      @interface.watch_list(@items.values[sel["out"]])
    end
  elsif key == @pref.get("keybindings")["anime_set_watched"] and not empty
    @interface.addWatched(path)
  elsif key == @pref.get("keybindings")["anime_undo_set_watched"]
    @interface.rmWatched
  elsif key == @pref.get("keybindings")["anime_set_unwatched"] and not empty
    @interface.rmWatched(path)
    moveCursor("down")
  end

  changed
  notify_observers
end

#refresh_attributesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/aniview/view/aiomenu.rb', line 9

def refresh_attributes
  if @items.length > 0
    unformatted_P = sum_attribute("p") / @items.length
  else
    unformatted_P = 0
  end

  if sum_attribute("d") > 0
    unformatted_Q = sum_attribute("W") * 100.0 / sum_attribute("d")
  else
    unformatted_Q = 0
  end
  @attributes = {
    "t" => @attributes["t"],
    "D" => Util.format_duration(sum_attribute("d")),
    "S" => Util.format_size(sum_attribute("s")),
    "P" => Util.format_progress(unformatted_P),
    "Q" => Util.format_progress(unformatted_Q),
    "c" => sum_attribute("c"),
    "w" => sum_attribute("w")
  }
end

#sum_attribute(k) ⇒ Object



32
33
34
# File 'lib/aniview/view/aiomenu.rb', line 32

def sum_attribute k
  @items.inject(0) { |mem, c| mem += c[0].attr[k] }
end