Class: VimGolfFinder::Challenge

Inherits:
Object
  • Object
show all
Defined in:
lib/vimgolf_finder/challenge.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/vimgolf_finder/challenge.rb', line 4

def description
  @description
end

#end_fileObject

Returns the value of attribute end_file.



5
6
7
# File 'lib/vimgolf_finder/challenge.rb', line 5

def end_file
  @end_file
end

#entriesObject

Returns the value of attribute entries.



3
4
5
# File 'lib/vimgolf_finder/challenge.rb', line 3

def entries
  @entries
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/vimgolf_finder/challenge.rb', line 3

def id
  @id
end

#start_fileObject

Returns the value of attribute start_file.



5
6
7
# File 'lib/vimgolf_finder/challenge.rb', line 5

def start_file
  @start_file
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/vimgolf_finder/challenge.rb', line 3

def title
  @title
end

#view_diffObject

Returns the value of attribute view_diff.



5
6
7
# File 'lib/vimgolf_finder/challenge.rb', line 5

def view_diff
  @view_diff
end

Class Method Details

.solve(id) ⇒ Object



48
49
50
51
52
53
54
55
# 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) }
end

Instance Method Details



7
8
9
10
11
12
13
14
# File 'lib/vimgolf_finder/challenge.rb', line 7

def print(index = 1)
  if self.solved?
    VimGolfFinder.ui.log "#{index}. \e[37m#{self.title}\e[0m - #{self.entries} entries (\e[33m#{self.id}\e[0m) [\u2713]"
  else
    VimGolfFinder.ui.log "#{index}. \e[37m#{self.title}\e[0m - #{self.entries} entries (\e[33m#{self.id}\e[0m)"
  end

end


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vimgolf_finder/challenge.rb', line 16

def print_detail
  VimGolfFinder.ui.say "#{self.title}", :white
  self.description.scan(/.{1,70}/).each do |string|
    VimGolfFinder.ui.log "#{string}\n"
  end

  VimGolfFinder.ui.log '-' * 50
  VimGolfFinder.ui.info 'Start File'
  VimGolfFinder.ui.log "#{self.start_file}"
  VimGolfFinder.ui.log '-' * 50
  VimGolfFinder.ui.info 'End File'
  VimGolfFinder.ui.log "#{self.end_file}"
  VimGolfFinder.ui.log '-' * 50
end

#solved?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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.eql?(self.id)
      return true
    end
  end

  return false
end