Class: Transducer::Generator
- Inherits:
-
Object
- Object
- Transducer::Generator
- Defined in:
- lib/transducer/generator.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#template_path ⇒ Object
readonly
Returns the value of attribute template_path.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(parsed_data, template_path: nil) ⇒ Generator
constructor
A new instance of Generator.
- #to_file(output_path) ⇒ Object
Constructor Details
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/transducer/generator.rb', line 8 def data @data end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
8 9 10 |
# File 'lib/transducer/generator.rb', line 8 def formatter @formatter end |
#template_path ⇒ Object (readonly)
Returns the value of attribute template_path.
8 9 10 |
# File 'lib/transducer/generator.rb', line 8 def template_path @template_path end |
Instance Method Details
#generate ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/transducer/generator.rb', line 16 def generate if @template_path render_template else generate_default end end |
#to_file(output_path) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/transducer/generator.rb', line 24 def to_file(output_path) require 'fileutils' FileUtils.mkdir_p(File.dirname(output_path)) File.write(output_path, generate) rescue Errno::EACCES raise FileError, "Permission denied: #{output_path}" rescue StandardError => e raise FileError, "Failed to write file: #{e.}" end |