Module: Muzak::Utils

Included in:
Index, Instance, Player::StubPlayer, Plugin::Cava, Plugin::Scrobble, Plugin::StubPlugin, Song
Defined in:
lib/muzak/utils.rb

Instance Method Summary collapse

Instance Method Details

#album_art?(filename) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/muzak/utils.rb', line 7

def album_art?(filename)
  File.basename(filename) =~ /(cover)|(folder).(jpg)|(png)/i
end

#debug(*args) ⇒ Object



48
49
50
51
52
# File 'lib/muzak/utils.rb', line 48

def debug(*args)
  return unless debug?

  output pretty(:yellow, "debug"), "[#{self.class.name}]", args
end

#debug?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/muzak/utils.rb', line 11

def debug?
  !!$debug
end

#error(*args) ⇒ Object



44
45
46
# File 'lib/muzak/utils.rb', line 44

def error(*args)
  output pretty(:red, "error"), "[#{self.class.name}]", args
end

#fail_arity(args, arity) ⇒ Object



64
65
66
# File 'lib/muzak/utils.rb', line 64

def fail_arity(args, arity)
  error "needed #{arity} arguments, got #{args.length}" unless args.length == arity
end

#info(*args) ⇒ Object



36
37
38
# File 'lib/muzak/utils.rb', line 36

def info(*args)
  output pretty(:green, "info"), args
end

#music?(filename) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/muzak/utils.rb', line 3

def music?(filename)
  [".mp3", ".flac", ".m4a", ".wav", ".ogg", ".oga", ".opus"].include?(File.extname(filename))
end

#output(box, *args) ⇒ Object



31
32
33
34
# File 'lib/muzak/utils.rb', line 31

def output(box, *args)
  msg = args.join(" ")
  puts "[#{box}] #{msg}"
end

#pretty(color = :none, str) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/muzak/utils.rb', line 19

def pretty(color = :none, str)
  colors = {
    none: 0,
    red: 31,
    green: 32,
    yellow: 33,
    blue: 34
  }

  "\e[#{colors[color]}m#{str}\e[0m"
end

#verbose(*args) ⇒ Object



54
55
56
57
58
# File 'lib/muzak/utils.rb', line 54

def verbose(*args)
  return unless verbose?

  output pretty(:blue, "verbose"), args
end

#verbose?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/muzak/utils.rb', line 15

def verbose?
  !!$verbose
end

#warn(*args) ⇒ Object



40
41
42
# File 'lib/muzak/utils.rb', line 40

def warn(*args)
  output pretty(:yellow, "warn"), args
end

#warn_arity(args, arity) ⇒ Object



60
61
62
# File 'lib/muzak/utils.rb', line 60

def warn_arity(args, arity)
  warn "expected #{arity} arguments, got #{args.length}" unless args.length == arity
end