class PryGem::GemSearch
@since 1.0.0
Constants
- API_ENDPOINT
Public Instance Methods
options(opt)
click to toggle source
# File lib/pry-gem/gem_search.rb, line 21 def options(opt) opt.on :l, :limit, 'Limit the number of results (max: 30)', default: 10, as: Integer, argument: true end
process(str)
click to toggle source
# File lib/pry-gem/gem_search.rb, line 28 def process(str) uri = URI.parse(API_ENDPOINT) uri.query = URI.encode_www_form(query: str) gems = JSON.parse(Net::HTTP.get(uri)) _pry_.pager.page list_as_string(gems, opts[:limit]) end
setup()
click to toggle source
# File lib/pry-gem/gem_search.rb, line 16 def setup require 'json' unless defined?(JSON) require 'net/http' unless defined?(Net::HTTP) end
Private Instance Methods
list_as_string(gems, limit = 10)
click to toggle source
# File lib/pry-gem/gem_search.rb, line 37 def list_as_string(gems, limit = 10) gems[0..limit - 1].map do |gem| name, version, info = gem.values_at 'name', 'version', 'info' "#{bold(name)} #{bold('v' + version)} \n#{info}\n\n" end.join end