Class: Rpa::Runner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Runner

Returns a new instance of Runner.



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
# File 'lib/rpa/runner.rb', line 9

def initialize(args)
  @options = Options.new(args).parse!.options

  if @options[:list_themes]
    puts Rpa.themes.join("\n")
    exit 0
  end

  options[:in_dir] = File.expand_path(options[:in_dir])
  @photos = Dir["#{options[:in_dir]}/**/*"].select do |f|
    %x{ file -ib "#{f}" }.to_s.strip.match(/^image/) && PHOTO_TYPES.any? { |t| f.match(/#{t}$/i) }
  end.sort do |x,y|
    Util.get_file_creation_time(x) <=> Util.get_file_creation_time(y)
  end

  if photos.length == 0
    raise "IN_DIR must contain at least one photo."
  end

  options[:out_dir] = File.expand_path(options[:out_dir])
  if File.exists?(options[:out_dir])
    unless File.directory?(options[:out_dir])
      raise "OUT_DIR exists and is not a directory."
    end
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/rpa/runner.rb', line 6

def options
  @options
end

#photosObject (readonly)

Returns the value of attribute photos.



6
7
8
# File 'lib/rpa/runner.rb', line 6

def photos
  @photos
end

Instance Method Details

#run!Object



36
37
38
39
40
# File 'lib/rpa/runner.rb', line 36

def run!
  FileUtils.mkdir_p(options[:out_dir]) unless File.directory?(options[:out_dir])
  p = Photos.new(photos, options)
  Page.new(p.photo_map, options)
end