Class: ShuttleCli::Bookmark

Inherits:
Object
  • Object
show all
Defined in:
lib/shuttle_cli/bookmark.rb

Constant Summary collapse

@@bookmark_number =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



3
4
5
# File 'lib/shuttle_cli/bookmark.rb', line 3

def children
  @children
end

#cmdObject

Returns the value of attribute cmd.



3
4
5
# File 'lib/shuttle_cli/bookmark.rb', line 3

def cmd
  @cmd
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/shuttle_cli/bookmark.rb', line 3

def name
  @name
end

#numberObject

Returns the value of attribute number.



3
4
5
# File 'lib/shuttle_cli/bookmark.rb', line 3

def number
  @number
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/shuttle_cli/bookmark.rb', line 3

def parent
  @parent
end

Class Method Details

.new_from_json(json, parent: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/shuttle_cli/bookmark.rb', line 7

def self.new_from_json json, parent: nil
  obj = new
  # We are looking at a deep nested hash if we have more than 1 values.
  if json.length == 1
    obj.name = json.keys.first
    obj.children = json.values.flatten.map do |h|
      # Recursive extract again
      new_from_json h, parent: obj
    end
  else
    obj.name = json[:name]
    obj.cmd = json[:cmd]
  end
  obj.parent = parent
  obj.number = @@bookmark_number
  @@bookmark_number += 1
  obj
end

Instance Method Details

#build_nameObject



26
27
28
29
30
31
32
# File 'lib/shuttle_cli/bookmark.rb', line 26

def build_name
  if parent
    "#{parent.name} - #{name}"
  else
    name
  end
end

#connectObject



38
39
40
# File 'lib/shuttle_cli/bookmark.rb', line 38

def connect
  system(cmd)
end

#to_aObject



34
35
36
# File 'lib/shuttle_cli/bookmark.rb', line 34

def to_a
  [number, build_name, cmd]
end