Class: Cfan122::YamlGenerator
- Inherits:
-
Object
- Object
- Cfan122::YamlGenerator
- Defined in:
- lib/cfan122/yaml_generator.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
- .generate_exam_agency(province = :ln, type = 'C1', subject = 3) ⇒ Object
- .generate_exam_info(province = :ln, type = 'C1', subject = 3) ⇒ Object
- .generate_exam_location(province = :ln, type = 'C1', subject = 3) ⇒ Object
- .generate_exam_subject(province = :ln, type = 'C1', subject = 3) ⇒ Object
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ YamlGenerator
constructor
A new instance of YamlGenerator.
- #open ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ YamlGenerator
Returns a new instance of YamlGenerator.
9 10 11 12 |
# File 'lib/cfan122/yaml_generator.rb', line 9 def initialize params = {} @file_name, @key, @text = params[:name], params[:key], params[:text] @path = "./lib/#{self.class.name.split("::")[0]}/meta/#{@file_name}.yml" end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/cfan122/yaml_generator.rb', line 7 def path @path end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
7 8 9 |
# File 'lib/cfan122/yaml_generator.rb', line 7 def text @text end |
Class Method Details
.generate_exam_agency(province = :ln, type = 'C1', subject = 3) ⇒ Object
34 35 36 |
# File 'lib/cfan122/yaml_generator.rb', line 34 def self.generate_exam_agency province = :ln, type = 'C1', subject = 3 YamlGenerator.new(name: province, key: "exam_agency_#{type}_#{subject}", text: ExamAgency.execute({province: province, type: type, subject: subject})).save end |
.generate_exam_info(province = :ln, type = 'C1', subject = 3) ⇒ Object
24 25 26 27 28 |
# File 'lib/cfan122/yaml_generator.rb', line 24 def self.generate_exam_info province = :ln, type = 'C1', subject = 3 self.generate_exam_subject province, type, subject self.generate_exam_agency province, type, subject self.generate_exam_location province, type, subject end |
.generate_exam_location(province = :ln, type = 'C1', subject = 3) ⇒ Object
38 39 40 |
# File 'lib/cfan122/yaml_generator.rb', line 38 def self.generate_exam_location province = :ln, type = 'C1', subject = 3 YamlGenerator.new(name: province, key: "exam_location_#{type}_#{subject}", text: ExamLocation.execute({province: province, type: type, subject: subject})).save end |
.generate_exam_subject(province = :ln, type = 'C1', subject = 3) ⇒ Object
30 31 32 |
# File 'lib/cfan122/yaml_generator.rb', line 30 def self.generate_exam_subject province = :ln, type = 'C1', subject = 3 YamlGenerator.new(name: province, key: "exam_subject_#{type}_#{subject}", text: ExamSubject.execute({province: province, type: type, subject: subject})).save end |
Instance Method Details
#open ⇒ Object
14 15 16 |
# File 'lib/cfan122/yaml_generator.rb', line 14 def open YAML.load_file(path) if File.exist?(path) end |
#save ⇒ Object
18 19 20 21 22 |
# File 'lib/cfan122/yaml_generator.rb', line 18 def save data = open || {} data[@key] = @text File.open(path, "w"){|file| file.write(data.to_yaml) } end |