-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell.rb
48 lines (39 loc) · 941 Bytes
/
cell.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Crossword
# Represent a whole crossword grid
class Grid
# Represent one cell in the crossword with its solution letter, user entry,
# possible number, and highlight state.
class Cell
attr_reader :letter, :user, :error
attr_accessor :number, :highlight
def self.from_text(line)
l, u, n = line.split ','
me = new(l)
me.number = n.to_i unless n.empty?
me.user = u
me
end
def initialize(letter)
@letter = letter
@user = ''
@number = 0
@highlight = :none
@error = false
end
def blank?
@letter == '.'
end
def user=(ltr)
@user = ltr
@error = user != '' && letter != user
end
# Empty means not filled in by user
def empty?
user.empty?
end
def to_text
"#{letter},#{user},#{number}"
end
end
end
end