Class: Quadtone::Tools::Init
Instance Attribute Summary
#profile, #verbose
Instance Method Summary
collapse
#parse_global_option, #parse_option, process_args, #process_environment
Instance Method Details
#get_inks ⇒ Object
51
52
53
54
|
# File 'lib/quadtone/tools/init.rb', line 51
def get_inks
@inks = prompt('Inks', @printer.inks, @printer.inks.join(','))
@inks = [@inks] unless @inks.kind_of?(Array)
end
|
#get_medium ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/quadtone/tools/init.rb', line 38
def get_medium
media = [
'Epson Velvet Fine Art',
'Epson Ultra Premium Presentation',
'Epson Premium Presentation',
'Epson Premium Luster',
'Hahnemuhle Bamboo',
'Southworth Antique Laid',
'Crane Museo',
]
@medium = prompt('Media', media, media[0])
end
|
#get_printer ⇒ Object
21
22
23
24
25
|
# File 'lib/quadtone/tools/init.rb', line 21
def get_printer
printers = CupsPrinter.get_all_printer_names.map { |n| Printer.new(n) }.select(&:quadtone?)
raise "No quadtone printers" if printers.empty?
@printer = prompt('Printer', printers, printers[0]) { |p| p.name }
end
|
#get_printer_options ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/quadtone/tools/init.rb', line 27
def get_printer_options
@printer_options = {}
@printer.options.each do |name, option|
if Printer::ImportantOptions.include?(name)
choices = option.choices.map { |c| c.choice }
default = option.choices.find { |c| c.choice == option.default_choice }
@printer_options[name] = prompt(name, choices, default)
end
end
end
|
#load_profile ⇒ Object
7
8
9
|
# File 'lib/quadtone/tools/init.rb', line 7
def load_profile
false
end
|
#prompt(label, values, default = nil, &block) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/quadtone/tools/init.rb', line 56
def prompt(label, values, default=nil, &block)
choices = {}
values.each_with_index { |value, i| choices[i + 1] = value }
STDERR.puts
STDERR.puts "#{label}:"
choices.each { |i, value| STDERR.puts '%2d. %s' % [i, block_given? ? yield(value) : value] }
STDERR.print "Choice" + (default ? " [#{block_given? ? yield(default) : default}]" : '') + "? "
selections = STDIN.gets.chomp
if selections.empty?
default
else
selections = selections.split(',').map(&:to_i)
case selections.length
when 0
default
when 1
choices[selections.first]
else
selections.map { |s| choices[s] }
end
end
end
|
#run(*args) ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/quadtone/tools/init.rb', line 11
def run(*args)
get_printer
get_printer_options
get_inks
get_medium
profile = Profile.new(printer: @printer, printer_options: @printer_options, inks: @inks, medium: @medium)
profile.save
;;warn "Created profile #{profile.name.inspect}"
end
|