Class: Funpack

Inherits:
Struct
  • Object
show all
Defined in:
lib/settings/lib/funpack.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#definitionsObject

Returns the value of attribute definitions

Returns:

  • (Object)

    the current value of definitions



3
4
5
# File 'lib/settings/lib/funpack.rb', line 3

def definitions
  @definitions
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/settings/lib/funpack.rb', line 3

def name
  @name
end

Class Method Details

.loadObject



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