class Ernest::Post
Attributes
api[R]
data[R]
file_path[R]
Public Class Methods
new(data, file_path, api)
click to toggle source
# File lib/ernest/post.rb, line 11 def initialize(data, file_path, api) @data = data @file_path = file_path @api = api end
parse_from_file(file_path, parser = MetadataParser, api = API)
click to toggle source
# File lib/ernest/post.rb, line 6 def self.parse_from_file(file_path, parser = MetadataParser, api = API) parsed_data = parser.new(File.open(file_path, 'rb').read).parse new(parsed_data, file_path, api) end
Public Instance Methods
save()
click to toggle source
# File lib/ernest/post.rb, line 17 def save if id? update else create end end
update_id(new_id)
click to toggle source
# File lib/ernest/post.rb, line 25 def update_id(new_id) unless id? new_file = File.read(file_path).sub("---\n", "---\nid: #{new_id}\n") File.write(file_path, new_file) end end
Private Instance Methods
create()
click to toggle source
# File lib/ernest/post.rb, line 44 def create api.with_data(data).post end
id()
click to toggle source
# File lib/ernest/post.rb, line 40 def id data.metadata['id'] end
id?()
click to toggle source
# File lib/ernest/post.rb, line 36 def id? !!id end
update()
click to toggle source
# File lib/ernest/post.rb, line 48 def update api.with_data(data).put(id) end