class Creq::Reader
Public Class Methods
call(file_name)
click to toggle source
# File lib/creq/reader.rb, line 10 def self.call(file_name) reader = new(file_name) reader.read end
new(file_name)
click to toggle source
# File lib/creq/reader.rb, line 27 def initialize(file_name) @file_name = file_name @file_reqs = Requirement.new(id: file_name) end
Public Instance Methods
read(enumerator = File.foreach(@file_name))
click to toggle source
@return [Requirement] requirements from file
# File lib/creq/reader.rb, line 16 def read(enumerator = File.foreach(@file_name)) each_req_text(enumerator) do |txt| req, lev = Parser.(txt) next unless req put_according_to_level(req, lev) end @file_reqs end
Protected Instance Methods
each_req_text(enumerator, &block)
click to toggle source
# File lib/creq/reader.rb, line 42 def each_req_text(enumerator, &block) quote, body = false, '' enumerator.each do |line| if line.start_with?('#') && !quote && !body.empty? block.call(body) body = '' end body << line quote = !quote if line.start_with?('```') end block.call(body) end
put_according_to_level(req, lev)
click to toggle source
# File lib/creq/reader.rb, line 32 def put_according_to_level(req, lev) parent = @file_reqs parent = parent.last while parent.last && (parent.level < (lev)) unless parent.level == lev puts "Wrong header level for [#{req.id}]" parent = @file_reqs end parent << req end