Class: Theoj::Paper

Inherits:
Object
  • Object
show all
Includes:
Git
Defined in:
lib/theoj/paper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Git

#change_branch, #clone_repo

Constructor Details

#initialize(repository_url, branch, path = nil) ⇒ Paper

Returns a new instance of Paper.



16
17
18
19
20
21
# File 'lib/theoj/paper.rb', line 16

def initialize(repository_url, branch, path = nil)
  @repository = repository_url
  @branch = branch
  find_paper path
  
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



13
14
15
# File 'lib/theoj/paper.rb', line 13

def branch
  @branch
end

#paper_metadataObject

Returns the value of attribute paper_metadata.



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

def 
  @paper_metadata
end

#paper_pathObject

Returns the value of attribute paper_path.



12
13
14
# File 'lib/theoj/paper.rb', line 12

def paper_path
  @paper_path
end

#repositoryObject

Returns the value of attribute repository.



11
12
13
# File 'lib/theoj/paper.rb', line 11

def repository
  @repository
end

#review_issueObject

Returns the value of attribute review_issue.



10
11
12
# File 'lib/theoj/paper.rb', line 10

def review_issue
  @review_issue
end

Class Method Details

.find_paper_path(search_path) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/theoj/paper.rb', line 66

def self.find_paper_path(search_path)
  paper_path = nil

  if Dir.exist? search_path
    Find.find(search_path).each do |path|
      if path =~ /paper\.tex$|paper\.md$/
        paper_path = path
        break
      end
    end
  end

  paper_path
end

.from_repo(repository_url, branch = "") ⇒ Object



81
82
83
# File 'lib/theoj/paper.rb', line 81

def self.from_repo(repository_url, branch = "")
  Paper.new(repository_url, branch, nil)
end

Instance Method Details

#authorsObject



23
24
25
# File 'lib/theoj/paper.rb', line 23

def authors
  @authors ||= parse_authors
end

#bibliography_pathObject



54
55
56
# File 'lib/theoj/paper.rb', line 54

def bibliography_path
  @paper_metadata["bibliography"]
end

#citation_authorObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/theoj/paper.rb', line 27

def citation_author
  surname = authors.first.last_name
  initials = authors.first.initials

  if authors.size > 1
    return "#{surname} et al."
  else
    return "#{surname}, #{initials}"
  end
end

#cleanupObject



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

def cleanup
  FileUtils.rm_rf(local_path) if Dir.exist?(local_path)
end

#dateObject



46
47
48
# File 'lib/theoj/paper.rb', line 46

def date
  @paper_metadata["date"]
end

#languagesObject



50
51
52
# File 'lib/theoj/paper.rb', line 50

def languages
  @languages ||= detect_languages
end

#local_pathObject



58
59
60
# File 'lib/theoj/paper.rb', line 58

def local_path
  @local_path ||= "tmp/#{SecureRandom.hex}"
end

#tagsObject



42
43
44
# File 'lib/theoj/paper.rb', line 42

def tags
  @paper_metadata["tags"]
end

#titleObject



38
39
40
# File 'lib/theoj/paper.rb', line 38

def title
  @paper_metadata["title"]
end