Class: Course::Assessment::Answer::ProgrammingFile

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/course/assessment/answer/programming_file.rb

Constant Summary collapse

LINE_SEPARATOR =

Separate the lines by \r \n or \r\n

/\r\n|\r|\n/
MAX_LINES =
ApplicationHTMLFormattersHelper::MAX_CODE_LINES
MAX_SIZE =
ApplicationHTMLFormattersHelper::MAX_CODE_SIZE

Instance Method Summary collapse

Instance Method Details

#lines(line_numbers = nil) ⇒ Array<String>

Returns the code at lines.

Parameters:

  • line_numbers (Integer|Range) (defaults to: nil)

    zero based line numbers, can be a Integer or Range.

Returns:

  • (Array<String>)

    the code lines. all lines will be returned if the line_numbers is not specified.


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/course/assessment/answer/programming_file.rb', line 24

def lines(line_numbers = nil)
  lines = content.split(LINE_SEPARATOR)

  case line_numbers
  when Range
    line_begin = line_numbers.min < 0 ? 0 : line_numbers.min
    lines[line_begin..line_numbers.max]
  when Integer
    lines[line_numbers]
  else
    lines
  end
end