Class: NotionCf::Template
- Inherits:
-
Object
- Object
- NotionCf::Template
- Defined in:
- lib/notion_cf/template.rb
Overview
Template class
Instance Attribute Summary collapse
-
#blueprints ⇒ Object
readonly
Returns the value of attribute blueprints.
Class Method Summary collapse
Instance Method Summary collapse
- #create(page_id) ⇒ Object
-
#initialize(blueprints: []) ⇒ Template
constructor
A new instance of Template.
Constructor Details
#initialize(blueprints: []) ⇒ Template
Returns a new instance of Template.
18 19 20 |
# File 'lib/notion_cf/template.rb', line 18 def initialize(blueprints: []) @blueprints = blueprints end |
Instance Attribute Details
#blueprints ⇒ Object (readonly)
Returns the value of attribute blueprints.
6 7 8 |
# File 'lib/notion_cf/template.rb', line 6 def blueprints @blueprints end |
Class Method Details
.build_from_file(file_path:) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/notion_cf/template.rb', line 9 def build_from_file(file_path:) raise ArgumentError, 'file_path is required' unless file_path string_key_hash = YAML.load_file(file_path) blueprints = JSON.parse(string_key_hash.to_json, symbolize_names: true) new(blueprints:) end |
Instance Method Details
#create(page_id) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/notion_cf/template.rb', line 22 def create(page_id) # ハッシュをyamlに変換する際に出力される!ruby/hash:Notion::Blockみたいな文字列を削除する yaml = YAML.dump(blueprints).gsub(%r{!ruby/(\w|:)*}, '') file_path = "templates/#{page_id}.yaml" File.open(file_path, 'w') { |file| file.write(yaml) } file_path end |