Class: StepsRecorderAnalyser
- Inherits:
-
Object
- Object
- StepsRecorderAnalyser
- Defined in:
- lib/sra2019.rb
Instance Attribute Summary collapse
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
-
#initialize(s, debug: false, savepath: '/tmp', title: 'Untitled') ⇒ StepsRecorderAnalyser
constructor
A new instance of StepsRecorderAnalyser.
- #to_html(filepath = File.join(@savepath, 'sra' + Time.now.to_i.to_s)) ⇒ Object
- #to_kbml(options = {}) ⇒ Object
- #to_pdf ⇒ Object
- #to_sliml ⇒ Object
-
#to_zip ⇒ Object
not yet working properly.
Constructor Details
#initialize(s, debug: false, savepath: '/tmp', title: 'Untitled') ⇒ StepsRecorderAnalyser
Returns a new instance of StepsRecorderAnalyser.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sra2019.rb', line 26 def initialize(s, debug: false, savepath: '/tmp', title: 'Untitled') @savepath, @title, @debug = savepath, title, debug content = RXFHelper.read(s).first puts ('content: ' + content.inspect).debug if @debug all_steps = parse_steps content @doc = build all_steps @steps = all_steps.select {|x| x[:user_comment]} end |
Instance Attribute Details
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
23 24 25 |
# File 'lib/sra2019.rb', line 23 def steps @steps end |
Instance Method Details
#to_html(filepath = File.join(@savepath, 'sra' + Time.now.to_i.to_s)) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/sra2019.rb', line 45 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
38 39 40 41 42 43 |
# File 'lib/sra2019.rb', line 38 def to_kbml(={}) @doc.xml end |
#to_pdf ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/sra2019.rb', line 104 def to_pdf() project = 'sra' + Time.now.to_i.to_s newdir = project pdf_file = File.join(@savepath, project, @title.gsub(/ /,'-') + '.pdf') html_file = File.join(@savepath, project, 'index.html') to_html(newdir) pdf = WickedPdf.new.pdf_from_html_file(html_file) File.write pdf_file, pdf end |
#to_sliml ⇒ Object
100 101 102 |
# File 'lib/sra2019.rb', line 100 def to_sliml() @sliml end |
#to_zip ⇒ Object
not yet working properly
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/sra2019.rb', line 119 def to_zip() project = 'sra' + Time.now.to_i.to_s newdir = File.join(@savepath, project) zipfile = File.join(@savepath, project + '.zip') to_html(newdir) Archive::Zip.archive(zipfile, File.join(@savepath, project)) 'saved to ' + zipfile end |