public
Description: Unlike my 'experiments' repository, these guys are deadly serious!
Homepage:
Clone URL: git://github.com/jonleighton/scripts.git
scripts / mount_board_lines.rb
100755 52 lines (40 sloc) 1.365 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env ruby
 
# Prints out the positions at which marks must be made on mount board when mounting a photo of
# a given size with a given border width.
 
class Size
  attr_accessor :width, :height
  
  def initialize(width, height)
    @width, @height = width, height
  end
end
 
STANDARD_SIZES = {
  "A4" => Size.new(210, 297),
  "4x6" => Size.new(102, 152),
  "5x7" => Size.new(127, 178),
  "8x10" => Size.new(203, 254),
  "8x12" => Size.new(203, 305)
}
 
def accumulate(array)
  array.inject([]) do |mem, val|
    mem << (mem.last || 0) + val
    mem
  end
end
 
print "Enter a WxH size in mm such as '142x204' or one of the standard sizes: #{STANDARD_SIZES.keys.join(", ")}: "
size = gets.chomp
 
if STANDARD_SIZES.keys.include?(size)
  size = STANDARD_SIZES[size]
else
  size = size.split("x")
  size = Size.new(size[0].to_i, size[1].to_i)
end
 
print "Enter the border width in mm: "
border_width = gets.chomp.to_i
 
print "By how many mms should each edge of the photo overlap the mount board? "
overlap = gets.chomp.to_i
 
horizontal = accumulate([0, border_width, size.width - (2 * overlap), border_width])
vertical = accumulate([0, border_width, size.height - (2 * overlap), border_width])
 
puts
puts "Markings need to be made at the following positions:"
puts "Horizontal edges: " + horizontal.join(", ")
puts "Vertical edges: " + vertical.join(", ")