class TableAnalysis::Core
Attributes
body_tds[RW]
header[RW]
pointer[RW]
table[RW]
x_max[RW]
y_max[RW]
Public Class Methods
new(header, table, body_tds)
click to toggle source
# File lib/table_analysis/core.rb, line 9 def initialize(header, table, body_tds) @header = header @table = table @body_tds = body_tds @pointer = [0, 0] @x_max = table.size - 1 @y_max = header.size - 1 end
Public Instance Methods
entrance()
click to toggle source
入场
# File lib/table_analysis/core.rb, line 19 def entrance @body_tds.each do |body_td| current_seat_position = seat_down reserved_seat(current_seat_position, body_td.rowspan, body_td.colspan) if body_td.reserved_seat? end @table end
is_unreserved_seat?()
click to toggle source
空座位
# File lib/table_analysis/core.rb, line 28 def is_unreserved_seat? @table[@pointer[0]][@pointer[1]].nil? ? true : false end
pointer_increase()
click to toggle source
# File lib/table_analysis/core.rb, line 63 def pointer_increase if @pointer[1] < @y_max @pointer[1] += 1 elsif @pointer[1] == @y_max && @pointer[0] < @x_max @pointer[1] = 0 @pointer[0] += 1 elsif @pointer[1] > @y_max && @pointer[0] > @x_max raise 'header_start_row取值错误' end end
reserved_seat(current_seat_position, rowspan, colspan)
click to toggle source
占座
# File lib/table_analysis/core.rb, line 46 def reserved_seat(current_seat_position, rowspan, colspan) (rowspan - 1).times do |n| @table[current_seat_position[0] + n + 1][current_seat_position[1]] = -1 end (colspan - 1).times do |m| @table[current_seat_position[0]][current_seat_position[1] + m + 1] = -1 (rowspan - 1).times do |n| @table[current_seat_position[0] + n + 1][current_seat_position[1] + m + 1] = -1 end end end
seat_down()
click to toggle source
坐下
# File lib/table_analysis/core.rb, line 33 def seat_down if is_unreserved_seat? @table[@pointer[0]][@pointer[1]] = seat_down_value current_seat_position = @pointer.dup pointer_increase current_seat_position else pointer_increase seat_down end end
seat_down_value()
click to toggle source
身份值
# File lib/table_analysis/core.rb, line 59 def seat_down_value @header[@pointer[1]] end