class VimGolfFinder::Challenge

Attributes

description[RW]
end_file[RW]
entries[RW]
id[RW]
start_file[RW]
title[RW]
view_diff[RW]

Public Class Methods

solve(id) click to toggle source
# File lib/vimgolf_finder/challenge.rb, line 48
def self.solve(id)
  path = "#{Dir.home}/.vimgolf_solves"
  unless File.exist?(path)
    File.new(path, File::CREAT|File::TRUNC|File::RDWR, 0644)
  end

  File.open(path, 'a') { |file| file.write("#{id}\n") }
end

Public Instance Methods

print(index = 1) click to toggle source
print_detail() click to toggle source
solved?() click to toggle source
# File lib/vimgolf_finder/challenge.rb, line 31
def solved?
  path = "#{Dir.home}/.vimgolf_solves"
  unless File.exist?(path)
    file = File.new(path, File::CREAT|File::TRUNC|File::RDWR, 0644)
  else
    file = File.new(path)
  end

  file.readlines.each do |line|
    if line.strip.eql?(self.id)
      return true
    end
  end

  return false
end