Class: AddWish

Inherits:
Djinni::Wish
  • Object
show all
Defined in:
lib/zoom/wish/add_wish.rb

Instance Method Summary collapse

Constructor Details

#initializeAddWish

Returns a new instance of AddWish.



32
33
34
35
36
37
# File 'lib/zoom/wish/add_wish.rb', line 32

def initialize
    @classes = Hash.new
    [Zoom::Profile].concat(Zoom::Profile.subclasses).each do |c|
        @classes[c.to_s] = c.new(c.to_s).to_s.split("\n")[1].strip
    end
end

Instance Method Details

#aliasesObject



4
5
6
# File 'lib/zoom/wish/add_wish.rb', line 4

def aliases
    return ["add", "new"]
end

#descriptionObject



8
9
10
# File 'lib/zoom/wish/add_wish.rb', line 8

def description
    return "Create a new profile"
end

#execute(args, djinni_env = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zoom/wish/add_wish.rb', line 12

def execute(args, djinni_env = {})
    if (args.split(" ").length != 2)
        usage
        return
    end

    config = djinni_env["config"]
    c, n = args.split(" ")

    if (config.has_profile?(n))
        puts("Profile already exists: #{n}")
    elsif (!@classes.has_key?(c))
        puts("Class does not exist: #{c}")
    else
        profiles = config.parse_profiles
        profiles[n] = Zoom::Profile.profile_by_name(c).new(n)
        config.set_profiles(profiles)
    end
end

#tab_complete(input, djinni_env = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/zoom/wish/add_wish.rb', line 39

def tab_complete(input, djinni_env = {})
    return [{}, "", ""] if (input.include?(" "))

    completions = @classes.select do |clas, desc|
        clas.downcase.start_with?(input.downcase)
    end

    return [completions, input, " "]
end

#usageObject



49
50
51
52
53
54
55
56
57
# File 'lib/zoom/wish/add_wish.rb', line 49

def usage
    puts("#{aliases.join(", ")} <class> <name>")
    puts("    #{description}.")
    puts
    puts("CLASSES")
    @classes.each do |clas, desc|
        puts("    #{clas}")
    end
end