Class: Pangrid::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/pangrid/xw.rb

Overview

solution = :black | :null | char | Rebus number = int borders = [:left, :right, :top, :bottom]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Cell

Returns a new instance of Cell.



36
37
38
# File 'lib/pangrid/xw.rb', line 36

def initialize(**args)
  args.each {|k,v| self.send :"#{k}=", v}
end

Instance Attribute Details

#bordersObject

Returns the value of attribute borders.



34
35
36
# File 'lib/pangrid/xw.rb', line 34

def borders
  @borders
end

#numberObject

Returns the value of attribute number.



34
35
36
# File 'lib/pangrid/xw.rb', line 34

def number
  @number
end

#solutionObject

Returns the value of attribute solution.



34
35
36
# File 'lib/pangrid/xw.rb', line 34

def solution
  @solution
end

Instance Method Details

#black?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/pangrid/xw.rb', line 40

def black?
  solution == :black
end

#has_bar?(s) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/pangrid/xw.rb', line 44

def has_bar?(s)
  borders.include? s
end

#inspectObject



65
66
67
68
69
70
71
72
# File 'lib/pangrid/xw.rb', line 65

def inspect
  case solution
  when :black; '#'
  when :null; '.'
  when Rebus; solution.inspect
  else; solution
  end
end

#rebus?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/pangrid/xw.rb', line 48

def rebus?
  solution.is_a?(Rebus)
end

#to_charObject



52
53
54
# File 'lib/pangrid/xw.rb', line 52

def to_char
  rebus? ? solution.to_char : solution
end

#to_wObject



56
57
58
59
60
61
62
63
# File 'lib/pangrid/xw.rb', line 56

def to_w
  case solution
  when :black; '#'
  when :null; '.'
  when Rebus; solution.inspect
  else; solution
  end
end