Class: MarsBase10::Subject
- Inherits:
-
Object
- Object
- MarsBase10::Subject
- Defined in:
- lib/mars_base_10/subject.rb
Instance Attribute Summary collapse
-
#current_item ⇒ Object
Returns the value of attribute current_item.
-
#scroll_limit ⇒ Object
Returns the value of attribute scroll_limit.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#at(index:) ⇒ Object
Returns the item at: the index: relative to the current_item.
- #contents ⇒ Object
- #contents=(a_contents_array) ⇒ Object
- #empty? ⇒ Boolean
- #index_width ⇒ Object
-
#initialize(title: 'Untitled', contents:) ⇒ Subject
constructor
A new instance of Subject.
- #item_count ⇒ Object
- #item_index_range ⇒ Object
- #line_at(index:) ⇒ Object
- #line_length_at(index:) ⇒ Object
- #max_content_width ⇒ Object
- #prepend_content(ary:) ⇒ Object
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_item ⇒ Object
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_limit ⇒ Object
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 |
#title ⇒ Object
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 |
#contents ⇒ Object
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
30 31 32 |
# File 'lib/mars_base_10/subject.rb', line 30 def empty? self.contents.empty? end |
#index_width ⇒ Object
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_count ⇒ Object
48 49 50 |
# File 'lib/mars_base_10/subject.rb', line 48 def item_count @contents.size end |
#item_index_range ⇒ Object
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_width ⇒ Object
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 |