Class: IniFile::Content
- Inherits:
-
Object
show all
- Defined in:
- lib/ini_file/content.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/ini_file/content.rb', line 37
def method_missing(method, *args, &block)
key = method.to_s.downcase.to_sym
if @content.has_key?(key)
if args.count > 0
raise ArgumentError.new("wrong number of arguments(#{args.count} for 0)")
elsif block_given?
raise ArgumentError.new("block syntax not supported")
elsif @content[key].is_a? Hash
return Content.from_hash(key, @content[key])
else
return @content[key]
end
else
super
end
end
|
Instance Attribute Details
#__name__ ⇒ Object
Returns the value of attribute __name__.
7
8
9
|
# File 'lib/ini_file/content.rb', line 7
def __name__
@__name__
end
|
Class Method Details
.parse(contents) ⇒ Object
56
57
58
59
60
|
# File 'lib/ini_file/content.rb', line 56
def self.parse(contents)
content = Content.new
content.instance_variable_set(:@content, Parser.parse(contents))
return content
end
|
Instance Method Details
#[](key) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/ini_file/content.rb', line 13
def [](key)
if @content[key].is_a? Hash
return Content.from_hash(key, @content[key])
else
return @content[key]
end
end
|
#each(&block) ⇒ Object
25
26
27
28
29
|
# File 'lib/ini_file/content.rb', line 25
def each(&block)
@content.each do |key, value|
yield(key, value) unless value.is_a? Hash
end
end
|
#each_section(&block) ⇒ Object
31
32
33
34
35
|
# File 'lib/ini_file/content.rb', line 31
def each_section(&block)
@content.each do |key, value|
yield(Content.from_hash(key, value)) if value.is_a? Hash
end
end
|
#empty? ⇒ Boolean
9
10
11
|
# File 'lib/ini_file/content.rb', line 9
def empty?
return @content.empty?
end
|
#to_hash ⇒ Object
21
22
23
|
# File 'lib/ini_file/content.rb', line 21
def to_hash
return Marshal.load( Marshal.dump(@content) )
end
|