class SafariBookmarksParser::Commands::DumpCommand

Attributes

output_parts[R]
output_style[R]

Public Class Methods

new(argv) click to toggle source
# File lib/safari_bookmarks_parser/commands/dump_command.rb, line 8
def initialize(argv)
  @output_style = :tree
  @output_parts = :all

  super
end

Public Instance Methods

run() click to toggle source
# File lib/safari_bookmarks_parser/commands/dump_command.rb, line 15
def run
  plist_parser = Parser.parse(@plist_path)

  result = select_output_parts(plist_parser)
  result = select_output_style(result)

  text = format_to_text(result)

  output_text(text)
end

Private Instance Methods

on_exclude_reading_list(parser) click to toggle source
# File lib/safari_bookmarks_parser/commands/dump_command.rb, line 83
def on_exclude_reading_list(parser)
  parser.on('-R', 'Exclude reading list') do
    @output_parts = :bookmarks
  end
end
on_list(parser) click to toggle source
# File lib/safari_bookmarks_parser/commands/dump_command.rb, line 71
def on_list(parser)
  parser.on('--list', 'Output as list') do
    @output_style = :list
  end
end
on_reading_list_only(parser) click to toggle source
# File lib/safari_bookmarks_parser/commands/dump_command.rb, line 77
def on_reading_list_only(parser)
  parser.on('-r', 'Output reading list only') do
    @output_parts = :reading_list
  end
end
on_tree(parser) click to toggle source
# File lib/safari_bookmarks_parser/commands/dump_command.rb, line 65
def on_tree(parser)
  parser.on('--tree', 'Output as tree (default)') do
    @output_style = :tree
  end
end
parse_options(argv) click to toggle source
# File lib/safari_bookmarks_parser/commands/dump_command.rb, line 48
def parse_options(argv)
  parser = OptionParser.new

  parser.banner = "Usage: #{parser.program_name} dump [options] [~/Library/Safari/Bookmarks.plist]"

  on_output_path(parser)
  on_output_format(parser)

  on_tree(parser)
  on_list(parser)

  on_reading_list_only(parser)
  on_exclude_reading_list(parser)

  do_parse(parser, argv)
end
select_output_parts(plist_parser) click to toggle source
# File lib/safari_bookmarks_parser/commands/dump_command.rb, line 28
def select_output_parts(plist_parser)
  case @output_parts
  when :all
    plist_parser.root_folder
  when :bookmarks
    plist_parser.root_folder_without_reading_list
  when :reading_list
    plist_parser.reading_list
  end
end
select_output_style(result) click to toggle source
# File lib/safari_bookmarks_parser/commands/dump_command.rb, line 39
def select_output_style(result)
  case @output_style
  when :tree
    result.to_h
  when :list
    result.to_a.map(&:to_h)
  end
end