Class: Lazylead::Screenshots

Inherits:
Requirement show all
Defined in:
lib/lazylead/task/accuracy/screenshots.rb

Overview

Check that ticket has screenshot(s). The screenshots should

1. present as attachments
2. has extension .jpg .jpeg .exif .tiff .tff .bmp .png .svg
3. mentioned in description with !<name>.<extension>|thumbnail! (read more https://bit.ly/3rusNgW)

Instance Attribute Summary

Attributes inherited from Requirement

#desc, #field, #score

Instance Method Summary collapse

Methods inherited from Requirement

#blank?, #non_blank?

Constructor Details

#initialize(minimum: 1, score: 2, ext: %w[.jpg .jpeg .exif .tiff .tff .bmp .png .svg]) ⇒ Screenshots

Returns a new instance of Screenshots.

Parameters:

  • minimum (defaults to: 1)

    The number of expected screenshots



37
38
39
40
41
# File 'lib/lazylead/task/accuracy/screenshots.rb', line 37

def initialize(minimum: 1, score: 2, ext: %w[.jpg .jpeg .exif .tiff .tff .bmp .png .svg])
  super "Screenshots", score, "Description,Attachments"
  @minimum = minimum
  @ext = ext
end

Instance Method Details

#passed(issue) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/lazylead/task/accuracy/screenshots.rb', line 43

def passed(issue)
  return false if issue.attachments.nil? || blank?(issue, "description")
  references = issue.description
                    .to_enum(:scan, /!.+!/)
                    .map { Regexp.last_match }
                    .map(&:to_s)
  return false if references.size < @minimum
  references.all? { |ref| pictures(issue).any? { |file| ref.include? file } }
end

#pictures(issue) ⇒ Object

Detect all pictures in ticket attachments and returns an array with file names.



54
55
56
57
58
# File 'lib/lazylead/task/accuracy/screenshots.rb', line 54

def pictures(issue)
  @pictures ||= issue.attachments
                     .select { |a| @ext.include? File.extname(a.filename).downcase }
                     .map(&:filename)
end