class Gemsi

Constants

GEMFILE
GEM_LINE_PATTERN
GEM_NAME_PATTERN
TAB_SIZE

Public Class Methods

main(path = nil) click to toggle source
# File lib/gemsi.rb, line 10
def main(path = nil)
  gems = parsed_gems(path)
  gem_names_arr = []
  gems.each do |gem|
    next if !gem[:is_parsed] || gem[:name].nil?

    gem_names_arr << gem[:name]
    gem[:spec] = gems_descriptions.detect { |description| description[:name] == gem[:name] }
  end
  name_size = gem_names_arr.max_by(&:length).size
  print_descriptions(gems, name_size)
end

Private Class Methods

build_description(spec) click to toggle source
# File lib/gemsi.rb, line 38
def build_description(spec)
  result = {
    name: spec.name,
    version: spec.version.to_s,
    summary: spec.summary,
    description: spec.description,
    homepage: spec.homepage,
    github_search: "https://github.com/search?q=#{spec.name}&ref=cmdform"
  }

  result[:full_description] = if result[:description] == result[:summary]
                                result[:description]
                              else
                                "#{result[:description]} #{result[:summary]}"
                              end
  result[:github_search] = result[:homepage]&.match(/github/) ? ' ' : "https://github.com/search?q=#{spec.name}&ref=cmdform"
  result
end
gems_descriptions() click to toggle source
# File lib/gemsi.rb, line 34
def gems_descriptions
  @gems_descriptions ||= Gem::Specification.all.map { |spec| build_description(spec) }
end
parsed_gems(path = nil) click to toggle source
# File lib/gemsi.rb, line 25
def parsed_gems(path = nil)
  gemfile = path || GEMFILE
  IO.read(gemfile).split("\n").map do |string|
    is_parsed = string.match(GEM_LINE_PATTERN) ? true : false
    name = is_parsed ? string.match(GEM_NAME_PATTERN)&.send(:[], 1) : nil
    { text: string, name: name, is_parsed: true }
  end
end
print_descriptions(gems, name_size = TAB_SIZE) click to toggle source
prn(text, tab = ' ' * TAB_SIZE) click to toggle source
# File lib/gemsi.rb, line 84
def prn(text, tab = ' ' * TAB_SIZE)
  puts "#{tab}#{text}"
end