Class: Videoreg::Config

Inherits:
Base
  • Object
show all
Defined in:
lib/videoreg/config.rb

Instance Method Summary collapse

Methods inherited from Base

logger, logger=, #logger=, #proc_alive?, #tpl, #which

Constructor Details

#initializeConfig

Returns a new instance of Config.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/videoreg/config.rb', line 5

def initialize
  @device = '/dev/video1'
  @resolution = '320x240'
  @fps = 25
  @duration = 10
  @filename = '#{time}-#{devname}.DEFAULT.avi'
  @command = 'ffmpeg -r #{fps} -s #{resolution} -f video4linux2 -r ntsc -i #{device} -vcodec  mjpeg -t #{duration} -an -y #{outfile}'
  @storage = '/tmp/#{devname}'
  @lockfile = '/tmp/videoreg.#{devname}.DEFAULT.lck'
  @store_max = 50
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object

set or get inner variable value depending on arguments count



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/videoreg/config.rb', line 39

def method_missing(*args)
  if args.length == 2 || args[0] =~ /=$/
    mname = args[0].to_s.gsub(/=/, '')
    value = args.last
    eval("@#{mname}='#{value}'")
  elsif args.length == 1
    tpl(eval("@#{args[0]}"))
  else
    super
  end
end

Instance Method Details

#base_cmdObject



33
34
35
# File 'lib/videoreg/config.rb', line 33

def base_cmd
  command.split(" ").first
end

#devnameObject



51
52
53
# File 'lib/videoreg/config.rb', line 51

def devname
  device.split('/').last
end

#loggerObject



21
22
23
# File 'lib/videoreg/config.rb', line 21

def logger
  @logger || self.class.logger
end

#outfileObject



29
30
31
# File 'lib/videoreg/config.rb', line 29

def outfile
  "#{storage}/#{filename}"
end

#store_max(*args) ⇒ Object



25
26
27
# File 'lib/videoreg/config.rb', line 25

def store_max(*args)
  (args.length > 0) ? (self.store_max=(args.shift)) : (@store_max.to_i)
end

#timeObject



17
18
19
# File 'lib/videoreg/config.rb', line 17

def time
  "#{Time.new.strftime("%Y%m%d-%H%M%S%L")}"
end