Class: RubygemsDownloads::Gem

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems_downloads/gem.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Gem

Returns a new instance of Gem.

Yields:

  • (_self)

Yield Parameters:



18
19
20
# File 'lib/rubygems_downloads/gem.rb', line 18

def initialize
  yield self
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



5
6
7
# File 'lib/rubygems_downloads/gem.rb', line 5

def author
  @author
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/rubygems_downloads/gem.rb', line 5

def name
  @name
end

#total_downloadsObject

Returns the value of attribute total_downloads.



5
6
7
# File 'lib/rubygems_downloads/gem.rb', line 5

def total_downloads
  @total_downloads
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/rubygems_downloads/gem.rb', line 5

def url
  @url
end

#versionObject

Returns the value of attribute version.



5
6
7
# File 'lib/rubygems_downloads/gem.rb', line 5

def version
  @version
end

#version_downloadsObject

Returns the value of attribute version_downloads.



5
6
7
# File 'lib/rubygems_downloads/gem.rb', line 5

def version_downloads
  @version_downloads
end

Class Method Details

.from_json(entry) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/rubygems_downloads/gem.rb', line 7

def self.from_json(entry)
  new do |gem|
    gem.name = entry[:name]
    gem.total_downloads = entry[:downloads]
    gem.version_downloads = entry[:version_downloads]
    gem.version = entry[:version]
    gem.author = entry[:authors]
    gem.url = entry[:project_uri]
  end
end

Instance Method Details

#==(other) ⇒ Object



37
38
39
# File 'lib/rubygems_downloads/gem.rb', line 37

def ==(other)
  other.class == self.class && other.state == state
end

#blank?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rubygems_downloads/gem.rb', line 33

def blank?
  !(name && author && total_downloads && version_downloads && version)
end

#stateObject



41
42
43
# File 'lib/rubygems_downloads/gem.rb', line 41

def state
  instance_variables.map { |variable| instance_variable_get(variable) }
end

#to_hObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/rubygems_downloads/gem.rb', line 22

def to_h
  {
    name: name,
    author: author,
    total_downloads: total_downloads,
    version_downloads: version_downloads,
    version: version,
    url: url
  }
end