module MappedCommon
Including class must respond to each_line
Public Instance Methods
count_lines_upto(stop_off)
click to toggle source
# File lib/cless/data.rb, line 25 def count_lines_upto(stop_off) cur = 0 nb = 0 while cur <= stop_off do cur = @ptr.index("\n", cur) if cur cur += 1 nb += 1 else break end end nb end
parse_header(allowed = [])
click to toggle source
# File lib/cless/data.rb, line 6 def parse_header(allowed = []) a = [] i = 0 each_line do |l| break unless l =~ %r{^\s*#(.*)$} i += 1 s = $1 case s when /^\s*cless:(.*)$/ s = $1.strip a += s.split_with_quotes when /^\s*(\w+):(.*)$/ k, v = $1.strip, $2.strip a << "--#{k}" << v if allowed.include?(k) end end return i, a end