Class: FileFormatterInput
- Inherits:
-
Object
- Object
- FileFormatterInput
show all
- Includes:
- Reloadable
- Defined in:
- lib/file_formatter_input.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/file_formatter_input.rb', line 7
def initialize(yaml_def)
raise 'No definition was provided' if yaml_def.size.zero?
@__yaml__ = yaml_def.dup
@data = FileFormatterInputData.new
input_def = YAML::load(yaml_def)
raise 'Hash was not provided.' unless input_def.is_a? Hash
raise 'No entries exist in the Hash' if input_def.length.zero?
input_def.each {|k,v| instance_eval("self.#{k}=v")}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/file_formatter_input.rb', line 44
def method_missing(sym, *args)
if sym.to_s == @data.__name__
@data
else
super(sym, *args)
end
end
|
Instance Attribute Details
#__yaml__ ⇒ Object
Returns the value of attribute __yaml__.
5
6
7
|
# File 'lib/file_formatter_input.rb', line 5
def __yaml__
@__yaml__
end
|
#file_name ⇒ Object
Returns the value of attribute file_name.
5
6
7
|
# File 'lib/file_formatter_input.rb', line 5
def file_name
@file_name
end
|
#file_path ⇒ Object
Returns the value of attribute file_path.
5
6
7
|
# File 'lib/file_formatter_input.rb', line 5
def file_path
@file_path
end
|
Instance Method Details
#data ⇒ Object
22
|
# File 'lib/file_formatter_input.rb', line 22
def data; @data; end
|
#data=(value) ⇒ Object
23
|
# File 'lib/file_formatter_input.rb', line 23
def data=(value); @data.data = value; end
|
#file_full_name ⇒ Object
25
|
# File 'lib/file_formatter_input.rb', line 25
def file_full_name; File.join(file_path, file_name); end
|
#parse(max_lines = nil) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/file_formatter_input.rb', line 27
def parse(max_lines=nil)
input = File.open(file_full_name)
i = 0
while !input.eof?
@data.__set_content__(input.readline)
yield @data
break if (i += 1) == max_lines
end
input.close
input = nil
end
|