Class: ItunesController::ItunesControllerDebug

Inherits:
Object
  • Object
show all
Defined in:
lib/itunesController/debug.rb

Constant Summary collapse

ANSI_BOLD =
"\033[1m"
ANSI_RESET =
"\033[0m"
ANSI_LGRAY =
"\033[0;37m"
ANSI_GRAY =
"\033[1;30m"

Class Method Summary collapse

Class Method Details

.getTrackDescription(track) ⇒ Object

Used to get a track description

Parameters:

  • track

    iTunes track

Returns:

  • the track information



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/itunesController/debug.rb', line 105

def self.getTrackDescription(track)
    result=[]
    if (track.show!=nil && track.show!="")
        result.push("Type: TV Episode")
        result.push("Show Name: "+track.show)
    else
        result.push("Type: Film")
    end
    result.push("Name: "+track.name)
    if (Platform.isWindows())
        result.push("Database ID: "+track.TrackDatabaseID.to_s)
        result.push("Location: "+track.location)
    else
        result.push("Database ID: "+track.databaseID.to_s)
        result.push("Location: "+track.location.path)
    end            
    return result.join("\n")
end

.pm(obj, *options) ⇒ Object

Used to print the methods of a object

Parameters:

  • obj (Object)

    The object

  • options


34
35
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
# File 'lib/itunesController/debug.rb', line 34

def self.pm(obj, *options)
    methods = obj.methods
    methods -= Object.methods unless options.include? :more
    filter = options.select {|opt| opt.kind_of? Regexp}.first
    methods = methods.select {|name| name =~ filter} if filter

    data = methods.sort.collect do |name|
        method = obj.method(name)
        if method.arity == 0
            args = "()"
        elsif method.arity > 0
            n = method.arity
            args = "(#{(1..n).collect {|i| "arg#{i}"}.join(", ")})"
        elsif method.arity < 0
            n = -method.arity
            args = "(#{(1..n).collect {|i| "arg#{i}"}.join(", ")}, ...)"
        end
        klass = $1 if method.inspect =~ /Method: (.*?)#/
        [name, args, klass]
    end
    max_name = data.collect {|item| item[0].size}.max
    max_args = data.collect {|item| item[1].size}.max
    data.each do |item|
        print " #{ANSI_BOLD}#{item[0].to_s.rjust(max_name)}#{ANSI_RESET}"
        print "#{ANSI_GRAY}#{item[1].ljust(max_args)}#{ANSI_RESET}"
        print "   #{ANSI_LGRAY}#{item[2]}#{ANSI_RESET}\n"
    end
    data.size
end

.pm_objc(obj, *options) ⇒ Object

Used to print the methods of a objc object

Parameters:

  • obj (Object)

    The object

  • options


91
92
93
94
# File 'lib/itunesController/debug.rb', line 91

def self.pm_objc(obj, *options)
    methods = obj.objc_methods 
    puts methods
end

.pm_ole(obj, *options) ⇒ Object

Used to print the methods of a ole object

Parameters:

  • obj (Object)

    The object

  • options


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/itunesController/debug.rb', line 67

def self.pm_ole(obj, *options)
    methods = obj.ole_methods 
    methods -= Object.methods unless options.include? :more
    filter = options.select {|opt| opt.kind_of? Regexp}.first
    methods = methods.select {|name| name =~ filter} if filter     
              
    data = methods.collect do |m|
        name = m.to_s               
        method = obj.ole_method(name)                 
        [name, "("+method.params.join(",")+")", method.return_type_detail,method.helpstring]
    end
    max_name = data.collect {|item| item[0].size}.max
    max_args = data.collect {|item| item[1].size}.max
    data.each do |item|
        print " #{ANSI_BOLD}#{item[0].to_s.rjust(max_name)}#{ANSI_RESET}"
        print "#{ANSI_GRAY}#{item[1].ljust(max_args)}#{ANSI_RESET}"
        print "   #{ANSI_LGRAY}#{item[2]}#{ANSI_RESET}\n"
    end
    data.size
end

.printTrack(track) ⇒ Object

Used to print track information

Parameters:

  • track

    iTunes track



98
99
100
# File 'lib/itunesController/debug.rb', line 98

def self.printTrack(track)
    puts getTrackDescription(track)
end