Skip to content

Commit

Permalink
Merge pull request #15 from apainintheneck/add-sort-by-downloads
Browse files Browse the repository at this point in the history
Adds sorting search results by total and verson downloads
  • Loading branch information
apainintheneck authored Dec 14, 2024
2 parents 993f41b + 32b9e05 commit 76d4af0
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [Unreleased]

- Add better support for showing the changelog
- Add ability to sort search results by total and version downloads

## [1.0.0] - 2024-12-08

Expand Down
13 changes: 11 additions & 2 deletions lib/gemview/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,24 @@ class Search < Dry::CLI::Command

argument :term, type: :string, required: true, desc: "Search term"

example %w[cli json]
option :downloads, values: %w[total version], desc: "Sort results by most downloads"

def call(term:, **)
example ["cli", "json --downloads=total"]

def call(term:, downloads: nil, **)
gems = Gem.search(term: term)

if gems.empty?
abort("Error: No gems found for the search term: #{term}")
end

case downloads
when "total"
gems.sort_by! { |gem| -gem.downloads }
when "version"
gems.sort_by! { |gem| -gem.version_downloads }
end

View.list(gems: gems)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/gemview/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Types
attribute :name, Types::Strict::String
attribute :downloads, Types::Strict::Integer
attribute :version, Types::Strict::String
attribute :version_downloads, Types::Strict::Integer
# Note: This is not returned by `Gems.search`.
attribute? :version_created_at, Types::Params::Time
attribute :authors, Types::Strict::String
Expand Down
30 changes: 30 additions & 0 deletions spec/gemview/__snapshots__/bluetooth-gem-search
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"name": "bluetooth",
"downloads": 6382,
"version": "1.0",
"version_downloads": 6382,
"authors": "Eric Hodel, Jeremie Castagna, Esteve Fernandez",
"info": "A bluetooth library for ruby",
"licenses": [],
Expand All @@ -15,6 +16,7 @@
"name": "tamashii-bluetooth",
"downloads": 2993,
"version": "0.1.0.beta.2",
"version_downloads": 1514,
"authors": "蒼時弦也",
"info": "The bluetooth implement for tamashii",
"licenses": [],
Expand All @@ -27,6 +29,7 @@
"name": "ruby-bluetooth",
"downloads": 2202,
"version": "0.0.1.1",
"version_downloads": 2195,
"authors": "ruby-bluetooth",
"info": "description - ruby-bluetooth - work in progress",
"licenses": [
Expand All @@ -41,6 +44,7 @@
"name": "cmus-bt",
"downloads": 7285,
"version": "0.1.3",
"version_downloads": 2117,
"authors": "Hirosho Kuwagata",
"info": "Bluetooth AVRCP wrapper for cmus.",
"licenses": [
Expand All @@ -55,6 +59,7 @@
"name": "ble",
"downloads": 13812,
"version": "1.0.0",
"version_downloads": 3468,
"authors": "Stephane D'Alu",
"info": "Allow access to Bluetooth Low Energy device from ruby",
"licenses": [
Expand All @@ -69,6 +74,7 @@
"name": "sphero_pwn",
"downloads": 4937,
"version": "0.0.1",
"version_downloads": 2940,
"authors": "Victor Costan",
"info": "This library is currently focused on reverse-engineering\n the undocumented parts of Sphero",
"licenses": [
Expand All @@ -83,6 +89,7 @@
"name": "bluebutton",
"downloads": 9212,
"version": "0.2.1",
"version_downloads": 5100,
"authors": "Samoilenko Yuri",
"info": "Simple daemon that allows you to execute action when bluetooth button shutter pressed. So you can control your PC by low energy button device and few scripts.\n",
"licenses": [
Expand All @@ -97,6 +104,7 @@
"name": "bluejam",
"downloads": 2100,
"version": "0.0.1",
"version_downloads": 2100,
"authors": "Francesco Palumbo",
"info": "Use bluetooth speaker with bluez-alsa and snd-aloop",
"licenses": [
Expand All @@ -111,6 +119,7 @@
"name": "shutter3",
"downloads": 7549,
"version": "0.1.3",
"version_downloads": 2495,
"authors": "James Robertson",
"info": "Uses the command `hcidump --raw` (see bluez-hcidump) to detect the bluetooth button events for a wireless bluetooth remote control shutter button.",
"licenses": [
Expand All @@ -125,6 +134,7 @@
"name": "sb-ble",
"downloads": 2427,
"version": "0.5.0",
"version_downloads": 2427,
"authors": "Fred Mitchell &amp; Sensorberg",
"info": "This supports LE Advertising",
"licenses": [
Expand All @@ -139,6 +149,7 @@
"name": "syncope",
"downloads": 3826,
"version": "0.0.0",
"version_downloads": 3826,
"authors": "Isam",
"info": "Syncope lets your apps knock out when you do",
"licenses": [],
Expand All @@ -151,6 +162,7 @@
"name": "hcitools_wrapper",
"downloads": 24114,
"version": "0.2.2",
"version_downloads": 3769,
"authors": "James Robertson",
"info": "Uses hcitool lescan + hcidump --raw to fetch the RSSI values from a Bluetooth device address.",
"licenses": [
Expand All @@ -165,6 +177,7 @@
"name": "lego-nxt",
"downloads": 5358,
"version": "0.3.0",
"version_downloads": 1710,
"authors": "Nathan Kleyn",
"info": "Ruby LEGO Mindstorms NXT 2.0 control via Bluetooth and USB. See http://github.com/nathankleyn/lego-nxt for more information.",
"licenses": [
Expand All @@ -179,6 +192,7 @@
"name": "hue_ble",
"downloads": 1755,
"version": "0.1.0",
"version_downloads": 1755,
"authors": "NeoCat",
"info": "Control color temperature, brightness, and color of Hue light bulbs which supports Bluetooth LE.",
"licenses": [
Expand All @@ -193,6 +207,7 @@
"name": "dozen",
"downloads": 4076,
"version": "1.1.0",
"version_downloads": 4075,
"authors": "Rob Fletcher",
"info": "A simple tool to pair your Sixaxis controller with any Bluetooth device. Derived from the sixpair.c source.",
"licenses": [
Expand All @@ -207,6 +222,7 @@
"name": "shutter3_morsecode",
"downloads": 4135,
"version": "0.1.1",
"version_downloads": 2471,
"authors": "James Robertson",
"info": "Uses a Shutter3 bluetooth device to publish SimplePubSub (SPS) messages using morse code.",
"licenses": [
Expand All @@ -221,6 +237,7 @@
"name": "ld3w",
"downloads": 12567,
"version": "0.2.2",
"version_downloads": 2098,
"authors": "James Robertson",
"info": "Reads the GPS data from a Nokia LD-3W GPS bluetooth receiver using the system command rfcomm.",
"licenses": [
Expand All @@ -235,6 +252,7 @@
"name": "rubyeddystoneurl",
"downloads": 2237,
"version": "1.0.0",
"version_downloads": 2237,
"authors": "Ferdinand E. Silva",
"info": "Ruby C Extension To Scan Eddystone-URL Bluetooth Low Energy Beacons",
"licenses": [],
Expand All @@ -247,6 +265,7 @@
"name": "bluez-profile",
"downloads": 3466,
"version": "1.1.2",
"version_downloads": 1662,
"authors": "Clive Andrews",
"info": "Create Custom Bluez Bluetooth Profiles",
"licenses": [
Expand All @@ -261,6 +280,7 @@
"name": "home_assistant-ble",
"downloads": 47134,
"version": "1.4.2",
"version_downloads": 2011,
"authors": "Grégoire Seux",
"info": "home-assistant does not cope well with bluetooth on raspberry pi. This gem sends event to HA.",
"licenses": [],
Expand All @@ -273,6 +293,7 @@
"name": "mi100",
"downloads": 20818,
"version": "1.0.0",
"version_downloads": 2954,
"authors": "Masami Yamakawa",
"info": "A ruby gem for controlling MI100 of monoxit through bluetooth virtual serial port.",
"licenses": [
Expand All @@ -287,6 +308,7 @@
"name": "hybridgroup-sphero",
"downloads": 37712,
"version": "1.5.2",
"version_downloads": 3488,
"authors": "The Hybrid Group",
"info": "A ruby gem for controlling your Sphero ball. Sends commands over the TTY\nprovided by the bluetooth connection.",
"licenses": [],
Expand All @@ -299,6 +321,7 @@
"name": "sphero",
"downloads": 19094,
"version": "1.5.3",
"version_downloads": 4484,
"authors": "The Hybrid Group",
"info": "A ruby gem for controlling your Sphero ball. Sends commands over the TTY\nprovided by the bluetooth connection.",
"licenses": [],
Expand All @@ -311,6 +334,7 @@
"name": "bluemoon",
"downloads": 3991,
"version": "0.0.1",
"version_downloads": 3991,
"authors": "Nathaniel Jones",
"info": "Enable or disable bluetooth on OS X based on your current location",
"licenses": [
Expand All @@ -325,6 +349,7 @@
"name": "robobuilder",
"downloads": 6428,
"version": "0.3.1",
"version_downloads": 3156,
"authors": "Jan Wedekind",
"info": "This Ruby extension defines the Robobuilder class for communicating a Robobuilder via the serial port or a Bluetooth serial connection.",
"licenses": [],
Expand All @@ -337,6 +362,7 @@
"name": "hybridgroup-mindset",
"downloads": 6340,
"version": "0.4",
"version_downloads": 3665,
"authors": "mkfs",
"info": "This module reads all data transmitted by a Neurosky\nMindset, which must already be paired in Bluetooth and have a Bluetooth serial\n(SPP) socket open. The gem provides the module and a command line utility for\nreading packets and either printing them to STDOUT in realtime, or serializing \nthem to STDOUT in JSON on exit.",
"licenses": [
Expand All @@ -351,6 +377,7 @@
"name": "wii4r",
"downloads": 4120,
"version": "0.5.0",
"version_downloads": 4120,
"authors": "KzMz, BuZz",
"info": "Ruby C Extension for controlling Wii Remote devices via bluetooth connection. Binding of C wiiuse library (www.wiiuse.net) ",
"licenses": [],
Expand All @@ -363,6 +390,7 @@
"name": "louis",
"downloads": 86123,
"version": "2.3.7",
"version_downloads": 2548,
"authors": "Sam Stelfox",
"info": "There is a public registry maintained by the IANA that is required to be used by all vendors operating in certains spaces. Ethernet, Bluetooth, and Wireless device manufacturers are all assigned unique prefixes. This database is available publicly online and can be used to identify the manufacturer of these devices. This library provides an easy mechanism to perform these lookups.",
"licenses": [
Expand All @@ -377,6 +405,7 @@
"name": "birdbrain",
"downloads": 13313,
"version": "0.9.6",
"version_downloads": 2514,
"authors": "fmorton",
"info": "This Ruby library allows students to use Ruby to read sensors and set motors and LEDs with the Birdbrain Technologies Hummingbird Bit and Finch 2. To use Ruby with the Hummingbird Bit or Finch 2, you must connect via bluetooth with the BlueBird Connector.",
"licenses": [
Expand All @@ -391,6 +420,7 @@
"name": "ruble",
"downloads": 250,
"version": "0.0.3.alpha",
"version_downloads": 250,
"authors": "Mike Vastola",
"info": "RuBLE is a ruby interface to the SimpleBLE library, providing a cross-platform DSL for interacting with Bluetooth Low Energy (BLE) devices.",
"licenses": [
Expand Down
12 changes: 12 additions & 0 deletions spec/gemview/__snapshots__/gems-by-author-bbatsov
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"name": "rubocop",
"downloads": 480421146,
"version": "1.69.1",
"version_downloads": 279434,
"version_created_at": "2024-12-03 09:03:08 UTC",
"authors": "Bozhidar Batsov, Jonas Arvidsson, Yuji Nakayama",
"info": "RuboCop is a Ruby code style checking and code formatting tool.\nIt aims to enforce the community-driven Ruby Style Guide.\n",
Expand Down Expand Up @@ -59,6 +60,7 @@
"name": "guard-rubocop",
"downloads": 14990046,
"version": "1.5.0",
"version_downloads": 5721654,
"version_created_at": "2021-08-28 03:52:42 UTC",
"authors": "Yuji Nakayama",
"info": "Guard::RuboCop automatically checks Ruby code style with RuboCop when files are modified.",
Expand Down Expand Up @@ -112,6 +114,7 @@
"name": "powerpack",
"downloads": 96666755,
"version": "0.1.3",
"version_downloads": 9595185,
"version_created_at": "2020-11-16 08:43:40 UTC",
"authors": "Bozhidar Batsov",
"info": "A few useful extensions to core Ruby classes.",
Expand Down Expand Up @@ -148,6 +151,7 @@
"name": "webpack-assets",
"downloads": 830034,
"version": "0.3.5",
"version_downloads": 184778,
"version_created_at": "2019-03-29 13:10:54 UTC",
"authors": "Sergey Nartimov",
"info": "Webpack Assets for Rails.",
Expand Down Expand Up @@ -189,6 +193,7 @@
"name": "rubocop-sequel",
"downloads": 2204854,
"version": "0.3.7",
"version_downloads": 36176,
"version_created_at": "2024-11-05 01:33:48 UTC",
"authors": "Timothée Peignier",
"info": "Code style checking for Sequel",
Expand All @@ -213,6 +218,7 @@
"name": "rubocop-rails",
"downloads": 178716517,
"version": "2.27.0",
"version_downloads": 2211846,
"version_created_at": "2024-10-26 08:16:39 UTC",
"authors": "Bozhidar Batsov, Jonas Arvidsson, Yuji Nakayama",
"info": "Automatic Rails code style checking tool.\nA RuboCop extension focused on enforcing Rails best practices and coding conventions.\n",
Expand Down Expand Up @@ -249,6 +255,7 @@
"name": "rubocop-performance",
"downloads": 183053121,
"version": "1.23.0",
"version_downloads": 791266,
"version_created_at": "2024-11-14 18:44:37 UTC",
"authors": "Bozhidar Batsov, Jonas Arvidsson, Yuji Nakayama",
"info": "A collection of RuboCop cops to check for performance optimizations\nin Ruby code.\n",
Expand Down Expand Up @@ -277,6 +284,7 @@
"name": "rubocop-minitest",
"downloads": 19826323,
"version": "0.36.0",
"version_downloads": 1676797,
"version_created_at": "2024-08-31 09:02:16 UTC",
"authors": "Bozhidar Batsov, Jonas Arvidsson, Koichi ITO",
"info": "Automatic Minitest code style checking tool.\nA RuboCop extension focused on enforcing Minitest best practices and coding conventions.\n",
Expand Down Expand Up @@ -305,6 +313,7 @@
"name": "rubocop-rake",
"downloads": 18633605,
"version": "0.6.0",
"version_downloads": 15753508,
"version_created_at": "2021-06-28 16:40:52 UTC",
"authors": "Masataka Pocke Kuwabara",
"info": "A RuboCop plugin for Rake",
Expand All @@ -329,6 +338,7 @@
"name": "rubocop-extension-generator",
"downloads": 13910,
"version": "0.5.2",
"version_downloads": 977,
"version_created_at": "2023-02-04 09:16:21 UTC",
"authors": "Masataka Pocke Kuwabara",
"info": "A generator of RuboCop's custom cops gem",
Expand Down Expand Up @@ -361,6 +371,7 @@
"name": "rubocop-rubycw",
"downloads": 985601,
"version": "0.1.6",
"version_downloads": 912052,
"version_created_at": "2021-05-23 07:40:34 UTC",
"authors": "Masataka Pocke Kuwabara",
"info": "Integrate RuboCop and ruby -cw",
Expand All @@ -385,6 +396,7 @@
"name": "rubocop-ast",
"downloads": 316381524,
"version": "1.36.2",
"version_downloads": 826979,
"version_created_at": "2024-11-27 15:27:09 UTC",
"authors": "Bozhidar Batsov, Jonas Arvidsson, Yuji Nakayama",
"info": " RuboCop's Node and NodePattern classes.\n",
Expand Down
Loading

0 comments on commit 76d4af0

Please sign in to comment.