Class: Metamatter::Readme

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/metamatter/readme.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(repository) ⇒ Readme

Returns a new instance of Readme.



9
10
11
# File 'lib/metamatter/readme.rb', line 9

def initialize(repository)
  @repository = repository
end

Instance Attribute Details

#repositoryObject

Returns the value of attribute repository.



7
8
9
# File 'lib/metamatter/readme.rb', line 7

def repository
  @repository
end

Instance Method Details

#contentsObject



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

def contents
  contents = github_response
  return Base64.decode64(contents.content)
end

#doiObject

Find the Zenodo DOI if it’s there Returns a DOI URL 10.5281/zenodo.9789 or nil



24
25
26
27
28
29
30
31
# File 'lib/metamatter/readme.rb', line 24

def doi
  if has_zenodo_badge?
    match = contents.match(/\d{2}.\d{4}\/zenodo.\d*/)[0]
    return match
  else
    return nil
  end
end

#github_responseObject



33
34
35
# File 'lib/metamatter/readme.rb', line 33

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

#has_zenodo_badge?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/metamatter/readme.rb', line 18

def has_zenodo_badge?
  contents.include?('zenodo.org/badge')
end