class MarsBase10::Subject
Attributes
first_row[RW]
scroll_limit[RW]
title[RW]
Public Class Methods
new(title: 'Untitled', contents:)
click to toggle source
# File lib/mars_base_10/subject.rb, line 7 def initialize(title: 'Untitled', contents:) @contents = contents @first_row = 0 @title = title end
Public Instance Methods
at(index:)
click to toggle source
Returns the item at: the index: relative to the first_row.
# File lib/mars_base_10/subject.rb, line 14 def at(index:) self.contents[self.first_row + index] end
cols()
click to toggle source
# File lib/mars_base_10/subject.rb, line 18 def cols return @cols if @cols @cols = @contents.inject(0) {|a, n| n.length > a ? n.length : a} end
contents()
click to toggle source
# File lib/mars_base_10/subject.rb, line 23 def contents @contents end
contents=(a_contents_array)
click to toggle source
# File lib/mars_base_10/subject.rb, line 27 def contents=(a_contents_array) @rows = nil $cols = nil @contents = a_contents_array end
rows()
click to toggle source
# File lib/mars_base_10/subject.rb, line 33 def rows return @rows if @rows @rows = @contents.size end
scroll_down()
click to toggle source
# File lib/mars_base_10/subject.rb, line 38 def scroll_down self.first_row = [self.first_row + 1, (self.rows - self.scroll_limit)].min end
scroll_up()
click to toggle source
# File lib/mars_base_10/subject.rb, line 42 def scroll_up self.first_row = [self.first_row - 1, 0].max end