Class: Semaph::Shells::Organisations::OrganisationsSelectCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/semaph/shells/organisations/organisations_select_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(organisations) ⇒ OrganisationsSelectCommand

Returns a new instance of OrganisationsSelectCommand.



9
10
11
12
13
# File 'lib/semaph/shells/organisations/organisations_select_command.rb', line 9

def initialize(organisations)
  @organisations = organisations
  @usage = "<organisation>"
  @help = "choose organisation"
end

Instance Attribute Details

#helpObject (readonly)

Returns the value of attribute help.



7
8
9
# File 'lib/semaph/shells/organisations/organisations_select_command.rb', line 7

def help
  @help
end

#usageObject (readonly)

Returns the value of attribute usage.



7
8
9
# File 'lib/semaph/shells/organisations/organisations_select_command.rb', line 7

def usage
  @usage
end

Instance Method Details

#completion(text) ⇒ Object



15
16
17
# File 'lib/semaph/shells/organisations/organisations_select_command.rb', line 15

def completion(text)
  @organisations.map { |org| org["host"].split(".").first }.grep(/^#{text}/).sort
end

#execute(name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/semaph/shells/organisations/organisations_select_command.rb', line 19

def execute(name)
  organisation = @organisations.find do |org|
    org["host"].split(".").first == name
  end

  unless organisation
    puts "There is no organisation called #{name}"
    return
  end

  ::Semaph::Shells::Organisation::OrganisationShell.new(organisation).push
end