class ElectricEye::ConfigEye

Attributes

config[R]

Initialise the method.

Public Class Methods

check_dir() click to toggle source

Check the directory and if it doesn't exist create it.

# File lib/electric_eye/config_eye.rb, line 11
def self.check_dir
  FileUtils.mkdir_p(CONFIG_DIR) unless Dir.exist?(CONFIG_DIR)
end
load() click to toggle source

Check that the config file exists.

# File lib/electric_eye/config_eye.rb, line 16
def self.load
  # Check if we have a config CONFIG_FILE
  ConfigEye.check_dir
  if File.exist?(CONFIG_FILE)
    Construct.load File.read(CONFIG_FILE)
  else
    # Create a new file with defaults
    Construct.new({duration: 600, wrap: 168, path: '~/recordings', threshold: 2, cameras: []})
  end
end
new() click to toggle source
# File lib/electric_eye/config_eye.rb, line 91
def initialize
  @config = ConfigEye.load
  save
end

Public Instance Methods

add_camera(camera, url) click to toggle source

Add camera

# File lib/electric_eye/config_eye.rb, line 33
def add_camera(camera, url)
  if camera.nil?
    warn "NO camera given"
  elsif url.nil?
    warn "NO url given"        
  else
    @config.cameras.push({name: camera, url: url})
    save
    info "Camera added"
  end
end
list_cameras() click to toggle source

List cameras in setup

# File lib/electric_eye/config_eye.rb, line 56
def list_cameras
  info "Cameras"
  tp @config.cameras, :name, :url => {width: 120}
end
remove_camera(camera) click to toggle source

Remove camera

# File lib/electric_eye/config_eye.rb, line 46
def remove_camera(camera)
  record = @config.cameras.bsearch{ |c| c[:name] == camera }
  if record
    @config.cameras.delete(record)
    save
  end
  info "Camera removed"
end
save() click to toggle source

Save the config file

# File lib/electric_eye/config_eye.rb, line 28
def save()
  File.open(CONFIG_FILE, 'w'){ |f| f.write config.to_yaml } # Store
end
set_duration(seconds) click to toggle source

Set duration

# File lib/electric_eye/config_eye.rb, line 69
def set_duration(seconds)
  @config.duration = seconds.to_i
  save
  info "Duration set to #{seconds} seconds"
end
set_path(dir) click to toggle source

Set path

# File lib/electric_eye/config_eye.rb, line 83
def set_path(dir)
  @config.path = dir
  save
  info "Path set to #{dir}"
end
set_threshold(level) click to toggle source

Set threshold

# File lib/electric_eye/config_eye.rb, line 76
def set_threshold(level)
  @config.threshold = level.to_i
  save
  info "Threshold set to #{level} objects"
end
set_wrap(wrap) click to toggle source

Set wrap

# File lib/electric_eye/config_eye.rb, line 62
def set_wrap(wrap)
  @config.wrap = wrap.to_i
  save
  info "Wrap set to #{wrap} files"
end