class MultiMovingsign::Settings
Settings
wrapper (reads/saves from/to YAML file via {load} / {#dump})
Attributes
mash[RW]
Public Class Methods
default_settings_path()
click to toggle source
Default path for the settings YAML file
# File lib/multi_movingsign/settings.rb, line 51 def self.default_settings_path File.join(ENV['HOME'], '.multi_movingsign.yml') end
load(path)
click to toggle source
Constructs a new {Settings} instance from settings saves in the specified YAML file
# File lib/multi_movingsign/settings.rb, line 11 def self.load(path) if File.exists? path self.new YAML.load(File.read(path)) else self.new({}) end end
new(hash = {})
click to toggle source
# File lib/multi_movingsign/settings.rb, line 19 def initialize(hash = {}) self.mash = Hashie::Mash.new hash end
Public Instance Methods
dump(path)
click to toggle source
Serializes (dumps) the settings into the specified YAML file
# File lib/multi_movingsign/settings.rb, line 44 def dump(path) File.open(path, 'w') do |f| f.write(self.mash.to_hash.to_yaml) end end
sign_paths=(paths)
click to toggle source
Sets the list of conifgured {Sign}s via an array of serial port paths
@example
settings.sign_paths = ['/dev/ttyUSB0', '/dev/ttyUSB1']
# File lib/multi_movingsign/settings.rb, line 39 def sign_paths=(paths) self.mash.signs = paths.map { |path| {'path' => path} } end
signs()
click to toggle source
Returns an array of the configured {Sign}s
# File lib/multi_movingsign/settings.rb, line 24 def signs self.mash.signs ||= [] self.mash.signs.map { |hash| Sign.load(hash) } end
signs?()
click to toggle source
true
if any signs are configured
# File lib/multi_movingsign/settings.rb, line 31 def signs? ! self.signs.empty? end