Class: StepsRecorderAnalyser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s, debug: false, savepath: '/tmp', title: 'Untitled') ⇒ StepsRecorderAnalyser

Returns a new instance of StepsRecorderAnalyser.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sra2019.rb', line 24

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

#stepsObject (readonly)

Returns the value of attribute steps.



21
22
23
# File 'lib/sra2019.rb', line 21

def steps
  @steps
end

Instance Method Details

#to_html(targetdir = 'sra' + Time.now.to_i.to_s) ⇒ Object



43
44
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
# File 'lib/sra2019.rb', line 43

def to_html(targetdir='sra' + Time.now.to_i.to_s)
  
  # save the image files to a file directory.
  # name the sub-directory using the date and time?

  filepath = File.join(@savepath, targetdir)
  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]}
        
        ![](images/screenshot#{i}.jpg)
"         
  
  end

html=<<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(html).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



36
37
38
39
40
41
# File 'lib/sra2019.rb', line 36

def to_kbml(options={})


  @doc.xml options

end

#to_pdfObject



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/sra2019.rb', line 99

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_zipObject

not yet working properly



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/sra2019.rb', line 114

def to_zip()
  
  project = 'sra' + Time.now.to_i.to_s
  newdir = project
  zipfile = project + '.zip'
  
  to_html(newdir)    

  Zip::ZipFile.open(zipfile, Zip::ZipFile::CREATE) do |x|
    x.add(project, File.join(@savepath, project))
  end
  
  'saved to ' + File.join(@savepath, zipfile)
  
end