Class: StepsRecorderAnalyser
- Inherits:
-
Object
- Object
- StepsRecorderAnalyser
- Defined in:
- lib/sra2019.rb
Instance Attribute Summary collapse
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#stop_time ⇒ Object
readonly
Returns the value of attribute stop_time.
Instance Method Summary collapse
- #import(s) ⇒ Object
-
#initialize(s, debug: false, savepath: '/tmp', title: 'Untitled') ⇒ StepsRecorderAnalyser
constructor
A new instance of StepsRecorderAnalyser.
-
#to_dx ⇒ Object
Returns a Dynarex object.
-
#to_html(filepath = File.join(@savepath, 'sra' + Time.now.to_i.to_s)) ⇒ Object
Writes the steps to an HTML file.
- #to_kbml(options = {}) ⇒ Object
-
#to_pdf(pdf_file = File.join(@savepath, 'sra' + Time.now.to_i.to_s, @title.gsub(/ /,'-') + '.pdf')) ⇒ Object
Writes the steps to a PDF file.
- #to_sliml ⇒ Object
- #to_srt ⇒ Object
- #to_subtitles ⇒ Object
-
#to_zip ⇒ Object
Compresses the HTML file directory to a ZIP file.
Constructor Details
#initialize(s, debug: false, savepath: '/tmp', title: 'Untitled') ⇒ StepsRecorderAnalyser
Returns a new instance of StepsRecorderAnalyser.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sra2019.rb', line 39 def initialize(s, debug: false, savepath: '/tmp', title: 'Untitled') @savepath, @title, @debug = savepath, title, debug raw_content, type = RXFHelper.read(s) content = if type == :file and File.extname(s) == '.zip' then Zip::ZipFile.new(s).instance_eval {read(to_a[0].name)} else raw_content end puts ('content: ' + content.inspect).debug if @debug @actions = parse_report content @all_steps = parse_steps content @doc = build @all_steps steps = @all_steps.select {|x| x[:user_comment]} @steps = steps.any? ? steps : @all_steps end |
Instance Attribute Details
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
36 37 38 |
# File 'lib/sra2019.rb', line 36 def start_time @start_time end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
36 37 38 |
# File 'lib/sra2019.rb', line 36 def steps @steps end |
#stop_time ⇒ Object (readonly)
Returns the value of attribute stop_time.
36 37 38 |
# File 'lib/sra2019.rb', line 36 def stop_time @stop_time end |
Instance Method Details
#import(s) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/sra2019.rb', line 61 def import(s) @dx = Dynarex.new @dx.import s end |
#to_dx ⇒ Object
Returns a Dynarex object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sra2019.rb', line 70 def to_dx() @dx = Dynarex.new 'instructions/instruction(step, imgsrc, description)' @dx.summary[:rawdoc_type] = 'rowx' @steps.each.with_index do |h, i| @dx.create step: i+1, imgsrc: "screenshot#{i+1}.jpg", description: h[:user_comment] || h[:desc] end @dx end |
#to_html(filepath = File.join(@savepath, 'sra' + Time.now.to_i.to_s)) ⇒ Object
Writes the steps to an HTML file
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/sra2019.rb', line 96 def to_html(filepath=File.join(@savepath, 'sra' + Time.now.to_i.to_s)) # save the image files to a file directory. # name the sub-directory using the date and time? imgpath = File.join(filepath, 'images') csspath = File.join(filepath, 'css') [filepath, imgpath, csspath].each {|x| FileUtils.mkdir x} @steps.each.with_index do |x, i| File.open(File.join(imgpath, "screenshot#{i}.jpg" ), 'wb') \ {|f| f.write(x[:screenshot]) } end rows = @steps.map.with_index do |x, i| li = " li markdown: #{x[:user_comment]}  " end @sliml=<<EOF html head title #{@title}: #{@steps.length} Steps (with Pictures) link rel='stylesheet' type='text/css' href='css/layout.css' media='screen, projection, tv' link rel='stylesheet' type='text/css' href='css/style.css' media='screen, projection, tv' link rel='stylesheet' type='text/css' href='css/print.css' media='print' body h1 #{@title} ol #{rows.join("\n").lstrip} EOF html = Rexle.new(Hlt.new(@sliml).to_html)\ .root.element('html').xml pretty: true File.write File.join(filepath, 'index.html'), html %w(layout style print).each \ {|x| File.write File.join(csspath, "%s.css" % x), ''} 'saved' end |
#to_kbml(options = {}) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/sra2019.rb', line 86 def to_kbml(={}) @doc.xml end |
#to_pdf(pdf_file = File.join(@savepath, 'sra' + Time.now.to_i.to_s, @title.gsub(/ /,'-') + '.pdf')) ⇒ Object
Writes the steps to a PDF file
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/sra2019.rb', line 192 def to_pdf(pdf_file=File.join(@savepath, 'sra' + Time.now.to_i.to_s, @title.gsub(/ /,'-') + '.pdf')) dir = File.dirname(pdf_file) html_file = File.join(dir, 'index.html') to_html(dir) pdf = WickedPdf.new.pdf_from_html_file(html_file) File.write pdf_file, pdf end |
#to_sliml ⇒ Object
151 152 153 |
# File 'lib/sra2019.rb', line 151 def to_sliml() @sliml end |
#to_srt ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/sra2019.rb', line 155 def to_srt() lines = to_subtitles.strip.lines.map.with_index do |x, i| raw_times, subtitle = x.split(/ /,2) start_time, end_time = raw_times.split('-',2) times = [("%02d:%02d:%02d" % ([0, 0 ] + start_time.split(/\D/)\ .map(&:to_i)).reverse.take(3).reverse), \ '-->', \ ("%02d:%02d:%02d" % ([0, 0 ] + end_time.split(/\D/).map(&:to_i))\ .reverse.take(3).reverse)].join(' ') [i+1, times, subtitle].join("\n") end lines.join("\n") end |
#to_subtitles ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/sra2019.rb', line 176 def to_subtitles() times = @all_steps.map(&:time).each_cons(2).map do |x| x.map do |sec| a = Subunit.new(units={minutes:60, hours:60}, seconds: sec).to_h.to_a a.map {|x|"%d%s" % [x[1], x[0][0]] }.join('') end.join('-') end times.zip(@all_steps.map(&:desc)).map {|x| x.join(' ')}.join("\n") end |
#to_zip ⇒ Object
Compresses the HTML file directory to a ZIP file
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/sra2019.rb', line 206 def to_zip() project = 'sra' + Time.now.to_i.to_s newdir = File.join(@savepath, project) zipfile = newdir + '.zip' to_html(File.join(newdir)) #to_pdf(File.join(newdir, @title.gsub(/ /,'-') + '.pdf')) Archive::Zip.archive(zipfile, newdir) zipfile end |