class RubyPocket::Cli::ListAction

Public Instance Methods

call(options) click to toggle source
# File lib/ruby_pocket/cli/list_action.rb, line 6
def call(options)
  favorites = FavoriteQuery.where(options.values).all
  render favorites
end

Private Instance Methods

add_placeholders(rows) click to toggle source
# File lib/ruby_pocket/cli/list_action.rb, line 30
def add_placeholders(rows)
  rows.each do |row|
    row.map! do |value|
      (value.to_s.empty? && '-') || value
    end
  end
end
render(favorites) click to toggle source
# File lib/ruby_pocket/cli/list_action.rb, line 13
def render(favorites)
  return puts 'Your Ruby Pocket is empty' if favorites.empty?

  headings = %w(ID Name Tags)
  rows = table_rows(favorites)

  puts Terminal::Table.new headings: headings, rows: rows
end
table_rows(favorites) click to toggle source
# File lib/ruby_pocket/cli/list_action.rb, line 22
def table_rows(favorites)
  rows = favorites.map do |f|
    [f.id, f.name, f.tags.map(&:name).join(',')]
  end

  add_placeholders(rows)
end