Class: DotOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/dot_options.rb,
lib/dot_options/version.rb

Constant Summary collapse

VERSION =
'0.1.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_options = nil, &block) ⇒ DotOptions

Returns a new instance of DotOptions.



5
6
7
8
9
10
11
12
# File 'lib/dot_options.rb', line 5

def initialize(base_options = nil, &block)
  @_key = nil
  @_parent = nil
  @_options = []
  @_full_path = []
  _build_options(base_options || {})
  instance_eval(&block) if block
end

Instance Attribute Details

#_full_pathObject

Returns the value of attribute _full_path.



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

def _full_path
  @_full_path
end

#_keyObject

Returns the value of attribute _key.



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

def _key
  @_key
end

#_optionsObject (readonly)

Returns the value of attribute _options.



2
3
4
# File 'lib/dot_options.rb', line 2

def _options
  @_options
end

#_parentObject

Returns the value of attribute _parent.



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

def _parent
  @_parent
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/dot_options.rb', line 14

def [](key)
  _options.include?(key.to_sym) ? send(key.to_sym) : nil
end

#inspectObject



18
19
20
# File 'lib/dot_options.rb', line 18

def inspect
  "<#{_options.map { |key| "#{key}: #{send(key).inspect}" }.join(', ')}>"
end

#to_hObject



26
27
28
29
30
31
32
# File 'lib/dot_options.rb', line 26

def to_h
  _options.to_h do |key|
    value = send key
    value = value.to_h if value.is_a? DotOptions
    [key, value]
  end
end

#to_sObject



22
23
24
# File 'lib/dot_options.rb', line 22

def to_s
  _flat_options.map { |key, value| "#{key} = #{value.inspect}" }.join "\n"
end