Class: MultiMovingsign::Settings
- Inherits:
-
Object
- Object
- MultiMovingsign::Settings
- Defined in:
- lib/multi_movingsign/settings.rb
Overview
Settings wrapper (reads/saves from/to YAML file via Settings.load / #dump)
Instance Attribute Summary collapse
-
#mash ⇒ Object
Returns the value of attribute mash.
Class Method Summary collapse
-
.default_settings_path ⇒ Object
Default path for the settings YAML file.
-
.load(path) ⇒ Object
Constructs a new Settings instance from settings saves in the specified YAML file.
Instance Method Summary collapse
-
#dump(path) ⇒ Object
Serializes (dumps) the settings into the specified YAML file.
-
#initialize(hash = {}) ⇒ Settings
constructor
A new instance of Settings.
-
#sign_paths=(paths) ⇒ Object
Sets the list of conifgured Signs via an array of serial port paths.
-
#signs ⇒ Object
Returns an array of the configured Signs.
-
#signs? ⇒ Boolean
true
if any signs are configured.
Constructor Details
#initialize(hash = {}) ⇒ Settings
Returns a new instance of Settings.
19 20 21 |
# File 'lib/multi_movingsign/settings.rb', line 19 def initialize(hash = {}) self.mash = Hashie::Mash.new hash end |
Instance Attribute Details
#mash ⇒ Object
Returns the value of attribute mash.
8 9 10 |
# File 'lib/multi_movingsign/settings.rb', line 8 def mash @mash end |
Class Method Details
.default_settings_path ⇒ Object
Default path for the settings YAML file
51 52 53 |
# File 'lib/multi_movingsign/settings.rb', line 51 def self.default_settings_path File.join(ENV['HOME'], '.multi_movingsign.yml') end |
.load(path) ⇒ Object
Constructs a new MultiMovingsign::Settings instance from settings saves in the specified YAML file
11 12 13 14 15 16 17 |
# 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 |
Instance Method Details
#dump(path) ⇒ Object
Serializes (dumps) the settings into the specified YAML file
44 45 46 47 48 |
# 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) ⇒ Object
Sets the list of conifgured MultiMovingsign::Signs via an array of serial port paths
39 40 41 |
# File 'lib/multi_movingsign/settings.rb', line 39 def sign_paths=(paths) self.mash.signs = paths.map { |path| {'path' => path} } end |
#signs ⇒ Object
Returns an array of the configured MultiMovingsign::Signs
24 25 26 27 28 |
# File 'lib/multi_movingsign/settings.rb', line 24 def signs self.mash.signs ||= [] self.mash.signs.map { |hash| Sign.load(hash) } end |
#signs? ⇒ Boolean
true
if any signs are configured
31 32 33 |
# File 'lib/multi_movingsign/settings.rb', line 31 def signs? ! self.signs.empty? end |