Class: ConfOptions::Standard

Inherits:
Hash
  • Object
show all
Defined in:
lib/confoptions.rb

Overview

Most common option. Only custom validator and getter supports

Direct Known Subclasses

Array, Bool, String

Instance Method Summary collapse

Constructor Details

#initialize(init_hash) ⇒ Standard

Returns a new instance of Standard.



4
5
6
# File 'lib/confoptions.rb', line 4

def initialize init_hash
    merge! init_hash
end

Instance Method Details

#getObject

parse otion into some (hash most likely) by using getter Proc



12
13
14
15
16
17
18
19
20
# File 'lib/confoptions.rb', line 12

def get
    if self[:getter].is_a? Proc
        self[:getter].call self
    elsif (private_methods + methods).include? :default_getter
        default_getter
    else
        fallback_getter
    end
end

#to_pairObject

return [name, value] pair



8
9
10
# File 'lib/confoptions.rb', line 8

def to_pair
    [self[:name],self[:value]]
end

#to_sObject

human readable representation



22
23
24
25
26
# File 'lib/confoptions.rb', line 22

def to_s
    get.collect { |k,v|
        k.to_s.capitalize.gsub('_',' ') + ': ' + v.to_s
    }.join "\n"
end