Module: Petrarca::Helpers
Instance Method Summary collapse
Instance Method Details
#load_ranges(range_file) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/petrarca/helpers.rb', line 19 def load_ranges(range_file) ranges = {} File.open(range_file, "r") do |f| f.each_line do |line| next if line.start_with?("#") g, r = line.chomp.split(":") ranges[g] = r.split(",") unless r.nil? end end ranges end |
#split_to_parts(body, ranges) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/petrarca/helpers.rb', line 6 def split_to_parts(body, ranges) ranges.map do |range_str| s, e = range_str.split("-") prefix = body[0, s.size] if Range.new(s.to_i, e.to_i).cover?(prefix.to_i) [prefix, body[(prefix.size)..]] else nil end end.compact.first end |