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.
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
load_metadata
end
|
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch.
13
14
15
|
# File 'lib/theoj/paper.rb', line 13
def branch
@branch
end
|
Returns the value of attribute paper_metadata.
14
15
16
|
# File 'lib/theoj/paper.rb', line 14
def paper_metadata
@paper_metadata
end
|
#paper_path ⇒ Object
Returns the value of attribute paper_path.
12
13
14
|
# File 'lib/theoj/paper.rb', line 12
def paper_path
@paper_path
end
|
#repository ⇒ Object
Returns the value of attribute repository.
11
12
13
|
# File 'lib/theoj/paper.rb', line 11
def repository
@repository
end
|
#review_issue ⇒ Object
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
#authors ⇒ Object
23
24
25
|
# File 'lib/theoj/paper.rb', line 23
def authors
@authors ||= parse_authors
end
|
#bibliography_path ⇒ Object
54
55
56
|
# File 'lib/theoj/paper.rb', line 54
def bibliography_path
@paper_metadata["bibliography"]
end
|
#citation_author ⇒ Object
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
|
#cleanup ⇒ Object
62
63
64
|
# File 'lib/theoj/paper.rb', line 62
def cleanup
FileUtils.rm_rf(local_path) if Dir.exist?(local_path)
end
|
#date ⇒ Object
46
47
48
|
# File 'lib/theoj/paper.rb', line 46
def date
@paper_metadata["date"]
end
|
#languages ⇒ Object
50
51
52
|
# File 'lib/theoj/paper.rb', line 50
def languages
@languages ||= detect_languages
end
|
#local_path ⇒ Object
58
59
60
|
# File 'lib/theoj/paper.rb', line 58
def local_path
@local_path ||= "tmp/#{SecureRandom.hex}"
end
|
42
43
44
|
# File 'lib/theoj/paper.rb', line 42
def tags
@paper_metadata["tags"] || @paper_metadata["keywords"]
end
|
#title ⇒ Object
38
39
40
|
# File 'lib/theoj/paper.rb', line 38
def title
@paper_metadata["title"]
end
|