Class: Hastie::ReportGenerator

Inherits:
ServerReader show all
Defined in:
lib/hastie/report_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServerReader

#get_server_config, #read_config_file, source_root

Instance Attribute Details

#piObject

Returns the value of attribute pi.



13
14
15
# File 'lib/hastie/report_generator.rb', line 13

def pi
  @pi
end

#report_idObject

Returns the value of attribute report_id.



13
14
15
# File 'lib/hastie/report_generator.rb', line 13

def report_id
  @report_id
end

#researcherObject

Returns the value of attribute researcher.



13
14
15
# File 'lib/hastie/report_generator.rb', line 13

def researcher
  @researcher
end

#titleObject

Returns the value of attribute title.



13
14
15
# File 'lib/hastie/report_generator.rb', line 13

def title
  @title
end

Class Method Details



9
10
11
# File 'lib/hastie/report_generator.rb', line 9

def self.banner
  "hastie create -p [PI] -r [RESERACHER] <OPTIONS>"
end

Instance Method Details

#check_destinationObject



98
99
100
101
102
103
104
# File 'lib/hastie/report_generator.rb', line 98

def check_destination
  if File.exists? self.destination_root
    say_status "error", "#{self.destination_root} already exists.", :red
    say_status "error", "please choose different output directory", :red
    exit(1)
  end
end

#check_name_availibleObject



90
91
92
93
94
95
96
# File 'lib/hastie/report_generator.rb', line 90

def check_name_availible
  if options[:published_reports] and options[:published_reports].include? report_id
    say_status "error", "Sorry, the #{report_id} is already a published report", :red
    say_status "error", "Please run again with a different name", :red
    exit(1)
  end
end

#create_data_dirObject



128
129
130
# File 'lib/hastie/report_generator.rb', line 128

def create_data_dir
  create_file File.join(data_dir, ".gitignore"), :verbose => true
end

#create_directory_structureObject



71
72
73
74
75
76
# File 'lib/hastie/report_generator.rb', line 71

def create_directory_structure
  unless options[:only_report]
    directory(File.join("templates", "project"), self.destination_root)
    self.destination_root = File.join(self.destination_root, Hastie.default_report_dir)
  end
end

#create_index_fileObject



123
124
125
126
# File 'lib/hastie/report_generator.rb', line 123

def create_index_file
  template_file = "templates/report_index.html.tt"
  template template_file, "index.html"
end

#create_report_fileObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/hastie/report_generator.rb', line 106

def create_report_file
  say_status "create", "report: #{options[:id]}"
  extension = determine_extension(options[:type])
  template_name = options[:template]
  options[:extension] = extension
  template_file = "templates/#{template_name}.#{extension}.tt"
  if !File.exists? File.join(File.dirname(__FILE__), template_file)
    say_status "error", "#{template_file} not present. Invalid Template.", :red
    exit(1)
  end
  report_filename = "#{options[:date]}-#{report_id}.#{extension}"
  say_status  "note", "report file: #{report_filename}"
  template template_file, report_filename
  options[:report_file] = report_filename
  options[:report_file_generated] = File.basename(report_filename, File.extname(report_filename)) + ".html"
end

#fetch_static_filesObject



132
133
134
135
136
137
138
139
140
141
# File 'lib/hastie/report_generator.rb', line 132

def fetch_static_files
  options[:server]["static"] ||= []
  options[:server]["static"].each do |static_file|
    static_path = File.join(options[:server_root], static_file)
    if File.exists? static_path
      say_status "copy", "#{static_path} to #{File.basename(destination_root)}"
      FileUtils.cp_r static_path, self.destination_root
    end
  end
end

#setup_destinationObject

output directory now means two different things depending on :only_report :only_report = true then :output means name of the report directory :only_report = false then :output means the starting location for the

project directory structure


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/hastie/report_generator.rb', line 55

def setup_destination
  if options[:only_report]
    if !options[:output]
      options[:output] = File.join(".", Hastie.default_report_dir)
    end
    self.destination_root = options[:output]
  else
    if !options[:output]
      options[:output] = "."
    end
    self.destination_root = File.join(options[:output], options[:id])
  end

  say_status "note", "root: #{self.destination_root}"
end

#setup_idObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/hastie/report_generator.rb', line 30

def setup_id
  if !options[:id]
    if options[:id_server] and options[:id_domain]
      id_server = Hastie::IdServer.new(options[:id_server], options[:id_domain])
      self.report_id = id_server.request_id(options[:pi], options[:researcher])
      options[:id] = self.report_id
    else
      say_status "error", "No ID server found", :red
      say_status "error", " Provide --id_server and --id_domain", :red
      say_status "error", " Or use --id to specify the ID of your report", :red
      exit(1)
    end
  else
    self.report_id = options[:id]
  end
  options[:name] = options[:id]

  say_status "note", "id: #{options[:id]}"
  say_status "note", "name: #{options[:name]}"
end

#setup_variablesObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/hastie/report_generator.rb', line 78

def setup_variables
  options[:pi] ||= "cbio"
  options[:researcher] ||= "cbio"
  options[:type] ||= "textile"
  options[:date] ||= "#{Time.now.strftime('%Y-%m-%d')}"
  self.title = options[:name].gsub("_", " ").capitalize
  options[:title] = self.title

  options[:analyst] ||= "cbio"
  options[:data_dir] ||= data_dir
end

#write_config_fileObject



143
144
145
146
147
# File 'lib/hastie/report_generator.rb', line 143

def write_config_file
  output_config_file = File.join(self.destination_root, Hastie.report_config_name)
  say_status "write", "#{File.basename(output_config_file)}"
  ConfigFile.write(output_config_file, options)
end