Class: PDD::Source
- Inherits:
-
Object
- Object
- PDD::Source
- Defined in:
- lib/pdd/source.rb
Overview
Source.
Instance Method Summary collapse
-
#initialize(file, path) ⇒ Source
constructor
Ctor.
-
#puzzles ⇒ Object
Fetch all puzzles.
Constructor Details
#initialize(file, path) ⇒ Source
Ctor.
file-
Absolute file name with source code
path-
Path to show (without full file name)
33 34 35 36 |
# File 'lib/pdd/source.rb', line 33 def initialize(file, path) @file = file @path = path end |
Instance Method Details
#puzzles ⇒ Object
Fetch all puzzles.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pdd/source.rb', line 39 def puzzles PDD.log.info "reading #{@path}..." re = %r{(.*(?:^|\s))@todo\s+#([\w\-\.:/]+)\s+(.+)} puzzles = [] lines = File.readlines(@file) lines.each_with_index do |line, idx| begin re.match(line) do |match| puzzles << puzzle(lines.drop(idx + 1), match, idx) end rescue ArgumentError => ex raise Error, ["in line ##{idx}", ex] end end lines.each_with_index do |line, idx| raise Error, "@todo found, but puzzle can't be parsed in line ##{idx}" \ if line =~ /.*(^|\s)@todo\s+[^#]/ end puzzles end |