Class: HomeworkReport::CommandLineTool
- Inherits:
-
Object
- Object
- HomeworkReport::CommandLineTool
- Defined in:
- lib/homework_report/command_line_tool.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#template_filepath ⇒ Object
Returns the value of attribute template_filepath.
Instance Method Summary collapse
-
#initialize(*args) ⇒ CommandLineTool
constructor
A new instance of CommandLineTool.
- #run ⇒ Object
Constructor Details
#initialize(*args) ⇒ CommandLineTool
Returns a new instance of CommandLineTool.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/homework_report/command_line_tool.rb', line 8 def initialize(*args) args = args.flatten self. = { output: :stdout } OptionParser.new do |opts| opts. = "Usage: #{opts.program_name} [options] TEMPLATE_FILE" opts.separator "Outcome: a HTML file/text is generated" opts.separator "Options:" opts end.parse! args unless self.template_filepath = args.shift raise RuntimeError, "TEMPLATE_FILE is required" end self.scope = Scope.new end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/homework_report/command_line_tool.rb', line 6 def @options end |
#scope ⇒ Object
Returns the value of attribute scope.
6 7 8 |
# File 'lib/homework_report/command_line_tool.rb', line 6 def scope @scope end |
#template_filepath ⇒ Object
Returns the value of attribute template_filepath.
6 7 8 |
# File 'lib/homework_report/command_line_tool.rb', line 6 def template_filepath @template_filepath end |
Instance Method Details
#run ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/homework_report/command_line_tool.rb', line 28 def run lambda {|path, &y| case path when :stdout then y.call $stdout when String then File.open path, "w", &y else raise RuntimeError end }.call .delete(:output) do |output| output << scope.render(template_filepath) output << "\n" end end |