Class: ShuttleCli::Bookmark
- Inherits:
-
Object
- Object
- ShuttleCli::Bookmark
- Defined in:
- lib/shuttle_cli/bookmark.rb
Constant Summary collapse
- @@bookmark_number =
1
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number ⇒ Object
Returns the value of attribute number.
-
#parent ⇒ Object
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
3 4 5 |
# File 'lib/shuttle_cli/bookmark.rb', line 3 def children @children end |
#cmd ⇒ Object
Returns the value of attribute cmd.
3 4 5 |
# File 'lib/shuttle_cli/bookmark.rb', line 3 def cmd @cmd end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/shuttle_cli/bookmark.rb', line 3 def name @name end |
#number ⇒ Object
Returns the value of attribute number.
3 4 5 |
# File 'lib/shuttle_cli/bookmark.rb', line 3 def number @number end |
#parent ⇒ Object
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_name ⇒ Object
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 |
#connect ⇒ Object
38 39 40 |
# File 'lib/shuttle_cli/bookmark.rb', line 38 def connect system(cmd) end |
#to_a ⇒ Object
34 35 36 |
# File 'lib/shuttle_cli/bookmark.rb', line 34 def to_a [number, build_name, cmd] end |