Class: Procfs2::ProcItem
- Inherits:
-
Object
show all
- Defined in:
- lib/procfs2/proc_item.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parent:) ⇒ ProcItem
Returns a new instance of ProcItem.
7
8
9
10
11
12
|
# File 'lib/procfs2/proc_item.rb', line 7
def initialize(parent:)
@_parent = parent
@_data = nil
_initialize_content
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/procfs2/proc_item.rb', line 43
def method_missing(method, *args, **kwargs)
if _data.respond_to?(:key?)
return _data[method.to_sym] if _data.key?(method.to_sym)
return _data[method.to_s] if _data.key?(method.to_s)
end
super
end
|
Instance Attribute Details
#_data ⇒ Object
Returns the value of attribute _data.
5
6
7
|
# File 'lib/procfs2/proc_item.rb', line 5
def _data
@_data
end
|
#_parent ⇒ Object
Returns the value of attribute _parent.
5
6
7
|
# File 'lib/procfs2/proc_item.rb', line 5
def _parent
@_parent
end
|
Class Method Details
.build(parent:) ⇒ Object
61
62
63
|
# File 'lib/procfs2/proc_item.rb', line 61
def build(parent:)
new(parent: parent)
end
|
Instance Method Details
#_filename ⇒ Object
14
15
16
|
# File 'lib/procfs2/proc_item.rb', line 14
def _filename
self.class::LABEL.to_s
end
|
#_path ⇒ Object
18
19
20
|
# File 'lib/procfs2/proc_item.rb', line 18
def _path
File.join([_parent&._path, _filename].compact)
end
|
#_raw_content ⇒ Object
22
23
24
25
26
|
# File 'lib/procfs2/proc_item.rb', line 22
def _raw_content
@_raw_content ||= File.read(_path) if File.file?(_path)
@_raw_content ||= ''
@_raw_content
end
|