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



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

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.



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

def steps
  @steps
end

Instance Method Details

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



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

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="html\nhead\n  title \#{@title}: \#{@steps.length} Steps (with Pictures)    \n  link rel='stylesheet' type='text/css' href='css/layout.css' media='screen,  projection, tv'\n  link rel='stylesheet' type='text/css' href='css/style.css' media='screen,  projection, tv'\n  link rel='stylesheet' type='text/css' href='css/print.css' media='print'\nbody\n  h1 \#{@title}\n\n  ol\n    \#{rows.join(\"\\n\").lstrip}\n"

  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



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

def to_kbml(options={})


  @doc.xml options

end

#to_zipObject

not yet working properly



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

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