Class: SafariBookmarksParser::BookmarkFolder

Inherits:
Object
  • Object
show all
Defined in:
lib/safari_bookmarks_parser/bookmark_folder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, folder_names:, children: []) ⇒ BookmarkFolder

Returns a new instance of BookmarkFolder.



7
8
9
10
11
# File 'lib/safari_bookmarks_parser/bookmark_folder.rb', line 7

def initialize(title:, folder_names:, children: [])
  @title = title
  @folder_names = folder_names
  @children = children
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



5
6
7
# File 'lib/safari_bookmarks_parser/bookmark_folder.rb', line 5

def children
  @children
end

#folder_namesObject (readonly)

Returns the value of attribute folder_names.



5
6
7
# File 'lib/safari_bookmarks_parser/bookmark_folder.rb', line 5

def folder_names
  @folder_names
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/safari_bookmarks_parser/bookmark_folder.rb', line 5

def title
  @title
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/safari_bookmarks_parser/bookmark_folder.rb', line 13

def empty?
  to_a.empty?
end

#to_aObject



17
18
19
20
21
# File 'lib/safari_bookmarks_parser/bookmark_folder.rb', line 17

def to_a
  results = []
  traverse(self, results)
  results
end

#to_hObject



23
24
25
# File 'lib/safari_bookmarks_parser/bookmark_folder.rb', line 23

def to_h
  { 'title' => title, 'folder_names' => folder_names, 'children' => children.map(&:to_h) }
end

#to_json(options) ⇒ Object



27
28
29
# File 'lib/safari_bookmarks_parser/bookmark_folder.rb', line 27

def to_json(options)
  to_h.to_json(options)
end