Sha256: 94d56a372377f4d8a5746008413aafa1693177af1c529b6121ecdf4fd8bc0127

Contents?: true

Size: 663 Bytes

Versions: 15

Compression:

Stored size: 663 Bytes

Contents

module Petrarca
  module Helpers

    extend self

    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


    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

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
petrarca-0.4.14 lib/petrarca/helpers.rb
petrarca-0.4.13 lib/petrarca/helpers.rb
petrarca-0.4.12 lib/petrarca/helpers.rb
petrarca-0.4.11 lib/petrarca/helpers.rb
petrarca-0.4.10 lib/petrarca/helpers.rb
petrarca-0.4.9 lib/petrarca/helpers.rb
petrarca-0.4.8 lib/petrarca/helpers.rb
petrarca-0.4.7 lib/petrarca/helpers.rb
petrarca-0.4.6 lib/petrarca/helpers.rb
petrarca-0.4.5 lib/petrarca/helpers.rb
petrarca-0.4.4 lib/petrarca/helpers.rb
petrarca-0.4.3 lib/petrarca/helpers.rb
petrarca-0.4.2 lib/petrarca/helpers.rb
petrarca-0.4.1 lib/petrarca/helpers.rb
petrarca-0.4.0 lib/petrarca/helpers.rb