Class: LNCS::Paper

Inherits:
Object
  • Object
show all
Defined in:
lib/lncs/paper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#manifestObject

Returns the value of attribute manifest.



8
9
10
# File 'lib/lncs/paper.rb', line 8

def manifest
  @manifest
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/lncs/paper.rb', line 8

def path
  @path
end

#proceedingsObject

Returns the value of attribute proceedings.



8
9
10
# File 'lib/lncs/paper.rb', line 8

def proceedings
  @proceedings
end

Instance Method Details

#authorsObject



18
19
20
# File 'lib/lncs/paper.rb', line 18

def authors
  manifest["authors"]
end

#copy_to(dst) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lncs/paper.rb', line 50

def copy_to(dst)
  FileUtils.mkdir_p(dst)

  if type == "zip"
    Zip::ZipFile.open(path) do |zipfile|
      zipfile.select { |file| zipfile.get_entry(file).file? }.each do |file|
        actions.create_file(File.join(dst, file.name), zipfile.read(file))
      end
    end
  else
    actions.copy_file(path, File.join(dst, name))
  end
end

#data_for_manifest(existing_data) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/lncs/paper.rb', line 64

def data_for_manifest(existing_data)
  if existing_data.key?(id)
    { id => existing_data[id] }
    
  elsif type == "zip"
    data = { pdf: paths_to_pdfs }
    
    case data[:pdf].size
    when 1
      data[:pdf] = data[:pdf].first
    when 0
      data[:FIXME] = "Change the PDF key to the path (relative, within the ZIP) of the compiled PDF."
    else
      data[:FIXME] = "Reduce the PDF key from an array to a single value which corresponds to the compiled PDF." 
    end

    { id => data }
  
  else
    {}
  end
end

#generate_title_to(dst, start_page) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lncs/paper.rb', line 34

def generate_title_to(dst, start_page)
  check_pdf_exists

  captured = title_page_from_manifest_or_latex
  captured += "\n" + authors_from_manifest_or_latex.map do |a| 
    a.gsub!(/(?<forename>\S*) (?<surname>.*)/, '\k<surname>, \k<forename>') if a   
    "\\index{#{a}}"
  end.join("\n") + "\n"

  captured += "\\maketitle\n"
  captured += "\\clearpage\n"
  captured += "\\setcounter{page}{#{start_page + page_count}}"

  actions.create_file(dst, captured)
end

#idObject



26
27
28
# File 'lib/lncs/paper.rb', line 26

def id
  name.match(/(\d+).(pdf|zip)/)[1]
end

#nameObject



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

def name
  File.basename(path)
end

#page_countObject



87
88
89
90
91
# File 'lib/lncs/paper.rb', line 87

def page_count
  check_pdf_exists
  
  PDF::Reader.new(open_pdf).page_count
end

#pdfObject



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

def pdf
  manifest["pdf"]
end

#titleObject



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

def title
  manifest["title"]
end

#typeObject



30
31
32
# File 'lib/lncs/paper.rb', line 30

def type
  name.match(/(pdf|zip)/)[1]
end