Class: Funpack
- Inherits:
-
Struct
- Object
- Struct
- Funpack
- Defined in:
- lib/settings/lib/funpack.rb
Instance Attribute Summary collapse
-
#definitions ⇒ Object
Returns the value of attribute definitions.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#definitions ⇒ Object
Returns the value of attribute definitions
3 4 5 |
# File 'lib/settings/lib/funpack.rb', line 3 def definitions @definitions end |
#name ⇒ Object
Returns the value of attribute name
3 4 5 |
# File 'lib/settings/lib/funpack.rb', line 3 def name @name end |
Class Method Details
.load ⇒ Object
4 5 6 7 |
# File 'lib/settings/lib/funpack.rb', line 4 def self.load funpackfile = JSON.load(File.read('funpack.json')) new(funpackfile['name'], funpackfile['settings']) end |
Instance Method Details
#settings(values) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/settings/lib/funpack.rb', line 9 def settings(values) settings = {} definitions.each do |defn| type, name, default = defn['type'], defn['name'], defn['default'] settings[name] = value(type, name, default, values[name]) end settings end |
#value(type, name, default, value) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/settings/lib/funpack.rb', line 20 def value(type, name, default, value) case type when 'boolean' !value.nil? when 'integer' Integer(value) rescue default else value || default end end |