class Pcoder::SourceCode

Attributes

basename[R]
body[R]
language_id[R]
task[R]

Public Class Methods

new(path) click to toggle source
# File lib/pcoder.rb, line 11
def initialize(path)
  @basename = File.basename(path)
  extname = File.extname(path)
  @language_id = to_language_id(extname)
  @task = @basename.split(/[_.]/)[1]
  @body = File.open(path).read
end

Public Instance Methods

set_task_option(task) click to toggle source
# File lib/pcoder.rb, line 19
def set_task_option(task)
  @task = task.split("_").last
end

Private Instance Methods

to_language_id(extname) click to toggle source
# File lib/pcoder.rb, line 25
def to_language_id(extname)
  case extname
  # C
  when ".c" then "1"
  # C++
  when ".cc", ".cpp" then "2"
  # Java
  when ".java" then "3"
  # PHP
  when ".php" then "5"
  # D
  when ".d" then "6"
  # Python
  when ".py" then "7"
  # Perl
  when ".pl" then "8"
  # Ruby
  when ".rb" then "9"
  # Haskell
  when ".hs" then "11"
  # Pascal
  when ".p", ".pp", ".pas" then "12"
  # HavaScript
  when ".js" then "15"
  # Visual Basic
  when ".vb" then "16"
  # Text
  when ".txt", ".text" then "17"
  else nil
  end
end