Class: Section
- Inherits:
-
Object
- Object
- Section
- Extended by:
- Forwardable
- Defined in:
- lib/coursegen/course/data/section.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#section ⇒ Object
readonly
Returns the value of attribute section.
Instance Method Summary collapse
- #[](ind) ⇒ Object
- #collapsed? ⇒ Boolean
- #find_by_short_name(sname) ⇒ Object
- #find_index(citem) ⇒ Object
- #has_lecture_numbers? ⇒ Boolean
- #has_subsections? ⇒ Boolean
-
#initialize(sect, citems, collapsed) ⇒ Section
constructor
A new instance of Section.
- #next_for(citem) ⇒ Object
- #previous_for(citem) ⇒ Object
Constructor Details
#initialize(sect, citems, collapsed) ⇒ Section
Returns a new instance of Section.
9 10 11 12 13 14 |
# File 'lib/coursegen/course/data/section.rb', line 9 def initialize (sect, citems, collapsed) @section = sect @collapsed = collapsed @citems = section_filter(citems) sort_pages end |
Instance Attribute Details
#section ⇒ Object (readonly)
Returns the value of attribute section.
6 7 8 |
# File 'lib/coursegen/course/data/section.rb', line 6 def section @section end |
Instance Method Details
#[](ind) ⇒ Object
28 29 30 |
# File 'lib/coursegen/course/data/section.rb', line 28 def [](ind) @citems[ind] end |
#collapsed? ⇒ Boolean
54 55 56 |
# File 'lib/coursegen/course/data/section.rb', line 54 def collapsed? @collapsed end |
#find_by_short_name(sname) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/coursegen/course/data/section.rb', line 20 def find_by_short_name(sname) matches = @citems.select { |c| sname == c.short_name} binding.pry if matches.length != 1 raise RuntimeError,"#{sname}: invalid reference in section \"#{@section}\"" if matches.length == 0 raise RunimeError, "#{sname}: duplicate referenced in section \"#{@section}\"" if matches.length != 1 matches[0] end |
#find_index(citem) ⇒ Object
16 17 18 |
# File 'lib/coursegen/course/data/section.rb', line 16 def find_index(citem) @citems.find_index(citem) end |
#has_lecture_numbers? ⇒ Boolean
50 51 52 |
# File 'lib/coursegen/course/data/section.rb', line 50 def has_lecture_numbers? false end |
#has_subsections? ⇒ Boolean
46 47 48 |
# File 'lib/coursegen/course/data/section.rb', line 46 def has_subsections? false end |
#next_for(citem) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/coursegen/course/data/section.rb', line 32 def next_for(citem) index = @citems.find_index(citem) raise ArgumentError, "invalid citem in next_for" if index.nil? new_index = [index, @citems.length-2].min @citems[new_index+1] end |
#previous_for(citem) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/coursegen/course/data/section.rb', line 39 def previous_for(citem) index = @citems.find_index(citem) raise ArgumentError, "invalid citem in next_for" if index.nil? new_index = [index, 1].max @citems[new_index-1] end |