Last active
August 29, 2015 14:16
-
-
Save yannvery/cac1694880ecf7dce3fa to your computer and use it in GitHub Desktop.
Launch it and search string on your gists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'octokit' | |
| require 'open-uri' | |
| class Gist | |
| attr_reader :description, :html_url | |
| def initialize params | |
| @id = params[:id] | |
| @description = params[:description] | |
| @html_url = params[:html_url] | |
| @files = [] | |
| params[:files].each do |file| | |
| @files << File.new(filename: file[1].filename, raw_url: file[1].raw_url) | |
| end | |
| end | |
| def files | |
| @files | |
| end | |
| def self.search gists, search | |
| results = [] | |
| gists.each do |gist| | |
| results << gist if gist.contains? search | |
| end | |
| results | |
| end | |
| def contains? search | |
| if [email protected]? | |
| return true if @description.include? search | |
| end | |
| @files.each do |file| | |
| return true if file.contains? search | |
| end | |
| false | |
| end | |
| end | |
| class File | |
| def initialize params | |
| @name = params[:filename] | |
| @url = params[:raw_url] | |
| @content ="" | |
| get_content | |
| end | |
| def get_content | |
| @content = open(@url){|f| f.read} | |
| end | |
| def contains? search | |
| if [email protected]? | |
| return true if @content.include? search | |
| end | |
| false | |
| end | |
| def content | |
| @content | |
| end | |
| end | |
| print "\rEnter your username : " | |
| username = gets.chomp | |
| print "\rSearch ? " | |
| search = gets.chomp | |
| puts "... Searching ...\r" | |
| Octokit.auto_paginate = true | |
| user = Octokit.user username | |
| gists = Octokit.gists user.login | |
| gg = [] | |
| gists.each do |g| | |
| gg << Gist.new(g) | |
| end | |
| results = Gist.search gg, search | |
| results.each do |r| | |
| puts "#{r.description} : #{r.html_url}" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment