Class: IChing::CastHexagram

Inherits:
Object
  • Object
show all
Defined in:
lib/i_ching/cast_hexagram.rb

Defined Under Namespace

Classes: InvalidCast

Constant Summary collapse

CHANGES =
{
  6 => 7,
  9 => 8
}
STABILIZATIONS =
{
  6 => 8,
  9 => 7
}
BINARY =
{
  7 => 1,
  8 => 0
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*lines) ⇒ CastHexagram

Returns a new instance of CastHexagram.



22
23
24
25
# File 'lib/i_ching/cast_hexagram.rb', line 22

def initialize(*lines)
  @lines = lines
  validate
end

Instance Attribute Details

#linesObject (readonly)

Returns the value of attribute lines.



20
21
22
# File 'lib/i_ching/cast_hexagram.rb', line 20

def lines
  @lines
end

Instance Method Details

#binaryObject



35
36
37
# File 'lib/i_ching/cast_hexagram.rb', line 35

def binary
  stabilize.lines.map { |line| BINARY[line] }.join("").to_i(2)
end

#changeObject



27
28
29
# File 'lib/i_ching/cast_hexagram.rb', line 27

def change
  CastHexagram.new(*process(CHANGES))
end

#changed_hexagramObject



43
44
45
# File 'lib/i_ching/cast_hexagram.rb', line 43

def changed_hexagram
  change.hexagram
end

#hexagramObject



39
40
41
# File 'lib/i_ching/cast_hexagram.rb', line 39

def hexagram
  Hexagram.get_by_binary(self.binary)
end

#stabilizeObject



31
32
33
# File 'lib/i_ching/cast_hexagram.rb', line 31

def stabilize
  CastHexagram.new(*process(STABILIZATIONS))
end