Class: MarsBase10::Subject

Inherits:
Object
  • Object
show all
Defined in:
lib/mars_base_10/subject.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: 'Untitled', contents:) ⇒ Subject

Returns a new instance of Subject.



7
8
9
10
# File 'lib/mars_base_10/subject.rb', line 7

def initialize(title: 'Untitled', contents:)
  @contents     = contents
  @title        = title
end

Instance Attribute Details

#current_itemObject

Returns the value of attribute current_item.



5
6
7
# File 'lib/mars_base_10/subject.rb', line 5

def current_item
  @current_item
end

#scroll_limitObject

Returns the value of attribute scroll_limit.



5
6
7
# File 'lib/mars_base_10/subject.rb', line 5

def scroll_limit
  @scroll_limit
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/mars_base_10/subject.rb', line 5

def title
  @title
end

Instance Method Details

#at(index:) ⇒ Object

Returns the item at: the index: relative to the current_item.



17
18
19
20
# File 'lib/mars_base_10/subject.rb', line 17

def at(index:)
  index = [1, index].max
  self.contents[index - 1]
end

#contentsObject



22
23
24
# File 'lib/mars_base_10/subject.rb', line 22

def contents
  @contents
end

#contents=(a_contents_array) ⇒ Object



26
27
28
# File 'lib/mars_base_10/subject.rb', line 26

def contents=(a_contents_array)
  @contents = a_contents_array
end

#empty?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/mars_base_10/subject.rb', line 30

def empty?
  self.contents.empty?
end

#index_widthObject



34
35
36
# File 'lib/mars_base_10/subject.rb', line 34

def index_width
  [self.item_count.to_s.length, 2].max
end

#item_countObject



48
49
50
# File 'lib/mars_base_10/subject.rb', line 48

def item_count
  @contents.size
end

#item_index_rangeObject



52
53
54
# File 'lib/mars_base_10/subject.rb', line 52

def item_index_range
  1..self.item_count
end

#line_at(index:) ⇒ Object



38
39
40
41
# File 'lib/mars_base_10/subject.rb', line 38

def line_at(index:)
  # The string here is the gutter followed by the window contents. improving the gutter is tbd.
  "#{"%0#{self.index_width}d" % (index)}  #{self.at(index: index)}"
end

#line_length_at(index:) ⇒ Object



43
44
45
46
# File 'lib/mars_base_10/subject.rb', line 43

def line_length_at(index:)
  return 0 if self.at(index: index).nil?
  (self.at(index: index)).length
end

#max_content_widthObject



56
57
58
# File 'lib/mars_base_10/subject.rb', line 56

def max_content_width
  @contents.inject(0) {|a, n| n.length > a ? n.length : a}
end

#prepend_content(ary:) ⇒ Object



12
13
14
# File 'lib/mars_base_10/subject.rb', line 12

def prepend_content(ary:)
  self.contents = ary + self.contents
end