Class: Timebomb::BombFile
- Inherits:
-
Object
- Object
- Timebomb::BombFile
- Defined in:
- lib/timebomb.rb
Overview
Handles reading and writing to a Timebomb file ‘*.tb`.
Constant Summary collapse
- EXTENSION =
".tb".freeze
Instance Attribute Summary collapse
-
#bomb ⇒ Object
readonly
Returns the value of attribute bomb.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ BombFile
constructor
A new instance of BombFile.
- #read ⇒ Object
- #write ⇒ Object
Constructor Details
Instance Attribute Details
#bomb ⇒ Object (readonly)
Returns the value of attribute bomb.
173 174 175 |
# File 'lib/timebomb.rb', line 173 def bomb @bomb end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
173 174 175 |
# File 'lib/timebomb.rb', line 173 def path @path end |
Instance Method Details
#read ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'lib/timebomb.rb', line 180 def read File.open(path, 'r') do |file| data = file.read frontmatter = Frontmatter.new(data) bomb.title = frontmatter.data.fetch("title") bomb.date = frontmatter.data.fetch("date") bomb.description = frontmatter.body end end |
#write ⇒ Object
190 191 192 193 194 195 196 197 198 199 |
# File 'lib/timebomb.rb', line 190 def write data = { "title" => bomb.title, "date" => bomb.date } File.open(path, 'w') do |file| file.puts data.to_yaml file.puts "---" file.puts file.puts bomb.description end end |