Class: Metamatter::Repository

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/metamatter.rb

Constant Summary

Constants included from Helpers

Helpers::MEDIA_TYPE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#client

Constructor Details

#initialize(repo_with_owner) ⇒ Repository

Public: Initialize a new Repository from a GitHub repo with owner

repo_with_owner - e.g. arfon/metamatter

Returns a Repository.



22
23
24
# File 'lib/metamatter.rb', line 22

def initialize(repo_with_owner)
  @owner, @name = repo_with_owner.split('/')
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/metamatter.rb', line 15

def name
  @name
end

#ownerObject

Returns the value of attribute owner.



14
15
16
# File 'lib/metamatter.rb', line 14

def owner
  @owner
end

Instance Method Details

#authorsObject

Public: Returns the full list of contributors to the repository sorted

by their contribution count

Returns authors hash.



48
49
50
# File 'lib/metamatter.rb', line 48

def authors
  Metamatter::Authors.new(self).list
end

#doiObject

Public: Returns any known DOIs for the repository

Returns a DOI string or nil



69
70
71
72
73
74
75
76
77
78
# File 'lib/metamatter.rb', line 69

def doi
  # Try README first
  if readme_doi = Metamatter::Readme.new(self).doi
    return readme_doi
  elsif datacite_doi = Metamatter::Datacite.new(self).doi
    return datacite_doi.first
  else
    return nil
  end
end

#extractObject

Public: Returns the full metadata for the repository

Returns metatdata hash.



36
37
38
39
40
41
42
# File 'lib/metamatter.rb', line 36

def extract
  return JSON.pretty_generate({ :repository => self.to_hash,
                                :authors => authors,
                                :tags => tags,
                                :license => license,
                                :doi => doi })
end

#github_responseObject

Private: The GitHub Repository response

Returns a cached Octokit response hash



83
84
85
# File 'lib/metamatter.rb', line 83

def github_response
  @github_response ||= client.repository(name_with_owner)
end

#licenseObject

Public: Returns the license detected for the repository

Returns license hash or nil



62
63
64
# File 'lib/metamatter.rb', line 62

def license
  Metamatter::License.new(self).license
end

#name_with_ownerObject

Public: Convenience method for returning the owner with name

Returns a string e.g. ‘arfon/metamatter’



29
30
31
# File 'lib/metamatter.rb', line 29

def name_with_owner
  [owner, name].join('/')
end

#tagsObject

Public: Returns the tags from the Algorithmia classification

Returns list of tags or nil.



55
56
57
# File 'lib/metamatter.rb', line 55

def tags
  Metamatter::Classification.new(self).tags
end

#to_hashObject

Private: Returns a summary hash for the repository

Returns a hash



90
91
92
93
94
95
96
97
# File 'lib/metamatter.rb', line 90

def to_hash
  {
    :name => github_response.name,
    :location => github_response.html_url,
    :description => github_response.description,
    :created_at => github_response.created_at
  }
end