Module: Muzak::Utils

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.resolve_command(cmd) ⇒ Object



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

def self.resolve_command(cmd)
  cmd.tr "-", "_"
end

.resolve_method(meth) ⇒ Object



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

def self.resolve_method(meth)
  meth.to_s.tr "_", "-"
end

Instance Method Details

#album_art?(filename) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#debug(*args) ⇒ Object



56
57
58
59
60
# File 'lib/muzak/utils.rb', line 56

def debug(*args)
  return unless debug?

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

#debug?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/muzak/utils.rb', line 19

def debug?
  !!$debug
end

#error(*args) ⇒ Object



52
53
54
# File 'lib/muzak/utils.rb', line 52

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

#fail_arity(args, arity) ⇒ Object



72
73
74
# File 'lib/muzak/utils.rb', line 72

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

#info(*args) ⇒ Object



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

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

#music?(filename) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#output(box, *args) ⇒ Object



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

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

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



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/muzak/utils.rb', line 27

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



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

def verbose(*args)
  return unless verbose?

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

#verbose?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/muzak/utils.rb', line 23

def verbose?
  !!$verbose
end

#warn(*args) ⇒ Object



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

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

#warn_arity(args, arity) ⇒ Object



68
69
70
# File 'lib/muzak/utils.rb', line 68

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