Class: Theoj::Paper
- Inherits:
-
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.
17
18
19
20
21
22
|
# File 'lib/theoj/paper.rb', line 17
def initialize(repository_url, branch, path = nil)
@repository = repository_url
@branch = branch
find_paper path
load_metadata
end
|
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch.
14
15
16
|
# File 'lib/theoj/paper.rb', line 14
def branch
@branch
end
|
Returns the value of attribute paper_metadata.
15
16
17
|
# File 'lib/theoj/paper.rb', line 15
def paper_metadata
@paper_metadata
end
|
#paper_path ⇒ Object
Returns the value of attribute paper_path.
13
14
15
|
# File 'lib/theoj/paper.rb', line 13
def paper_path
@paper_path
end
|
#repository ⇒ Object
Returns the value of attribute repository.
12
13
14
|
# File 'lib/theoj/paper.rb', line 12
def repository
@repository
end
|
#review_issue ⇒ Object
Returns the value of attribute review_issue.
11
12
13
|
# File 'lib/theoj/paper.rb', line 11
def review_issue
@review_issue
end
|
Class Method Details
.find_paper_path(search_path) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/theoj/paper.rb', line 67
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
82
83
84
|
# File 'lib/theoj/paper.rb', line 82
def self.from_repo(repository_url, branch = "")
Paper.new(repository_url, branch, nil)
end
|
Instance Method Details
#authors ⇒ Object
24
25
26
|
# File 'lib/theoj/paper.rb', line 24
def authors
@authors ||= parse_authors
end
|
#bibliography_path ⇒ Object
55
56
57
|
# File 'lib/theoj/paper.rb', line 55
def bibliography_path
@paper_metadata["bibliography"]
end
|
#citation_author ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/theoj/paper.rb', line 28
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
|
#cleanup ⇒ Object
63
64
65
|
# File 'lib/theoj/paper.rb', line 63
def cleanup
FileUtils.rm_rf(local_path) if Dir.exist?(local_path)
end
|
#date ⇒ Object
47
48
49
|
# File 'lib/theoj/paper.rb', line 47
def date
@paper_metadata["date"]
end
|
#languages ⇒ Object
51
52
53
|
# File 'lib/theoj/paper.rb', line 51
def languages
@languages ||= detect_languages
end
|
#local_path ⇒ Object
59
60
61
|
# File 'lib/theoj/paper.rb', line 59
def local_path
@local_path ||= "tmp/#{SecureRandom.hex}"
end
|
43
44
45
|
# File 'lib/theoj/paper.rb', line 43
def tags
@paper_metadata["tags"] || @paper_metadata["keywords"]
end
|
#title ⇒ Object
39
40
41
|
# File 'lib/theoj/paper.rb', line 39
def title
@paper_metadata["title"]
end
|