class Geminfo::Stats

Class name

Public Class Methods

new(name) click to toggle source

initialize all instance variables

# File lib/geminfo.rb, line 20
def initialize(name)
        #Converts gemname to lowercase
        @gemname = name.downcase

        #parse links
        @link = 'http://rubygems.org/api/v1/gems/' + @gemname + ".json"

        #Exception handling
        begin
                @page_content = Net::HTTP.get(URI.parse(@link))
        rescue
                abort "Internet Connection cannot be established"
        end
        #Exception handling
        begin
                @data_file = JSON.parse(@page_content)
        rescue
                abort "Check you have entered the right Gem name"
        end  
end

Public Instance Methods

authors() click to toggle source
# File lib/geminfo.rb, line 64
def authors
        #returns gem's authors' names
        @data_file["authors"]
end
bugURL() click to toggle source
# File lib/geminfo.rb, line 124
def bugURL
        #returns gem's bug tracking URL
        @data_file["bug_tracker_uri"]
end
docURL() click to toggle source
# File lib/geminfo.rb, line 109
def docURL
        #returns gem's documentation URL
        @data_file["documentation_uri"]
end
gemURL() click to toggle source
# File lib/geminfo.rb, line 89
def gemURL
        #returns gem's URL
        @data_file["gem_uri"]
end
homepage() click to toggle source
# File lib/geminfo.rb, line 99
def homepage
        #returns gem's dedicated website
        @data_file["homepage_uri"]
end
info() click to toggle source
# File lib/geminfo.rb, line 69
def info
        #returns gem's description
        @data_file["info"]
end
latest() click to toggle source
# File lib/geminfo.rb, line 53
def latest
        #returns Gem's total download for latest version
        total = @data_file["version_downloads"]
        total = total.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
end
latestversion() click to toggle source
# File lib/geminfo.rb, line 59
def latestversion
        #returns latest version of gem
        @data_file["version"]
end
licenses() click to toggle source
# File lib/geminfo.rb, line 74
def licenses
        #returns gem's licenses
        @data_file["licenses"]
end
mailURL() click to toggle source
# File lib/geminfo.rb, line 114
def mailURL
        #returns gem's mailing list URL
        @data_file["mailing_list_uri"]
end
metadata() click to toggle source
# File lib/geminfo.rb, line 79
def metadata
        #returns gem's metadata
        return @data_file["metadata"].length == 0? "empty metadata" : metadata
end
name() click to toggle source

Methods to return values

# File lib/geminfo.rb, line 42
def name
        #returns gem name
        return @gemname
end
projectURL() click to toggle source
# File lib/geminfo.rb, line 94
def projectURL
        #returns gem's project URL
        @data_file["project_uri"]
end
sha() click to toggle source
# File lib/geminfo.rb, line 84
def sha
        #returns gem's Secure Hash Algoruthm 256 Checksum
        @data_file["sha"]
end
sourceURL() click to toggle source
# File lib/geminfo.rb, line 119
def sourceURL
        #returns gem's source-code URL
        @data_file["source_code_uri"]
end
total() click to toggle source
# File lib/geminfo.rb, line 47
def total
        #return Gem's total downloads for all versions
        total = @data_file["downloads"]
        total = total.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
end
wikiURL() click to toggle source
# File lib/geminfo.rb, line 104
def wikiURL
        #returns gem's wiki URL
        @data_file["wiki_uri"]
end