Top Level Namespace
Defined Under Namespace
Modules: GitGraph
Instance Method Summary collapse
Instance Method Details
#compare_languages(client) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gitGraph/github/feature/compare_languages.rb', line 4 def compare_languages(client) # languages will be the array that will be used # to form labels in the chart languages = [] # datasets will hold the data that we obtain for each user # based on github querying for their languages datasets = [] client.each do |name, user| new_dataset = { label: name, data: {} } client.client.repositories(name).each do |repo| client.client.languages(repo.full_name).attrs.each_pair do |lang, value| languages.push(lang) unless languages.include?(lang) new_dataset[:data][lang] ||= 0 new_dataset[:data][lang] += value end end datasets.push(new_dataset) end # sort the languages languages.sort! # go through the languages, and if a dataset does not have that language # as part of its data array, default it to 0 languages.each do |lang| datasets.each { |dataset| dataset[:data][lang] ||= 0} end # convert the data hash to an array datasets.each { |dataset| dataset[:data] = dataset[:data].to_a } # sort on the array by key datasets.each { |dataset| dataset[:data].sort! { |a, b| a[0] <=> b[0] } } # each value in the array represents bytes of code written in a language. # convert each value in the array to kilobytes written in each language datasets.each { |dataset| dataset[:data].each { |data| data[1] /= 1024} } # return a new graphable data item GitGraph::GitHub::GraphableData.new(labels: languages, datasets: datasets) end |
#require_files(directory) ⇒ Object
1 2 3 4 5 6 7 8 9 |
# File 'lib/utils.rb', line 1 def require_files(directory) Dir.glob(directory).each do |file| if File.directory?(file) require_files(file << "/*") else require_relative file end end end |