Class: TableAnalysis::Core
- Inherits:
-
Object
- Object
- TableAnalysis::Core
- Defined in:
- lib/table_analysis/core.rb
Instance Attribute Summary collapse
-
#body_tds ⇒ Object
Returns the value of attribute body_tds.
-
#header ⇒ Object
Returns the value of attribute header.
-
#pointer ⇒ Object
Returns the value of attribute pointer.
-
#table ⇒ Object
Returns the value of attribute table.
-
#x_max ⇒ Object
Returns the value of attribute x_max.
-
#y_max ⇒ Object
Returns the value of attribute y_max.
Instance Method Summary collapse
-
#entrance ⇒ Object
入场.
-
#initialize(header, table, body_tds) ⇒ Core
constructor
A new instance of Core.
-
#is_unreserved_seat? ⇒ Boolean
空座位.
- #pointer_increase ⇒ Object
-
#reserved_seat(current_seat_position, rowspan, colspan) ⇒ Object
占座.
-
#seat_down ⇒ Object
坐下.
-
#seat_down_value ⇒ Object
身份值.
Constructor Details
#initialize(header, table, body_tds) ⇒ Core
Returns a new instance of Core.
9 10 11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
#body_tds ⇒ Object
Returns the value of attribute body_tds.
7 8 9 |
# File 'lib/table_analysis/core.rb', line 7 def body_tds @body_tds end |
#header ⇒ Object
Returns the value of attribute header.
7 8 9 |
# File 'lib/table_analysis/core.rb', line 7 def header @header end |
#pointer ⇒ Object
Returns the value of attribute pointer.
7 8 9 |
# File 'lib/table_analysis/core.rb', line 7 def pointer @pointer end |
#table ⇒ Object
Returns the value of attribute table.
7 8 9 |
# File 'lib/table_analysis/core.rb', line 7 def table @table end |
#x_max ⇒ Object
Returns the value of attribute x_max.
7 8 9 |
# File 'lib/table_analysis/core.rb', line 7 def x_max @x_max end |
#y_max ⇒ Object
Returns the value of attribute y_max.
7 8 9 |
# File 'lib/table_analysis/core.rb', line 7 def y_max @y_max end |
Instance Method Details
#entrance ⇒ Object
入场
19 20 21 22 23 24 25 |
# 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? ⇒ Boolean
空座位
28 29 30 |
# File 'lib/table_analysis/core.rb', line 28 def is_unreserved_seat? @table[@pointer[0]][@pointer[1]].nil? ? true : false end |
#pointer_increase ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# 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) ⇒ Object
占座
46 47 48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
坐下
33 34 35 36 37 38 39 40 41 42 43 |
# 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 ⇒ Object
身份值
59 60 61 |
# File 'lib/table_analysis/core.rb', line 59 def seat_down_value @header[@pointer[1]] end |