Sha256: ce8e5cee2654f650c5175b5bc11c2c2c1df917c70d356acce23642e97f852090

Contents?: true

Size: 576 Bytes

Versions: 15

Compression:

Stored size: 576 Bytes

Contents

require 'rogdl'

class CartfileParser
  attr_reader :contents, :type
  def initialize(type, contents)
    @contents = contents
    @type = type || 'runtime'
  end

  def to_json
    Oj.dump(dependencies, mode: :compat) unless contents.nil?
  end

  def dependencies
    parse.inject([]) do |deps, dep|
      deps.push({
        name: dep[1],
        version: [dep[2],dep[3]].join(' ') || ">= 0",
        type: type,
      })
    end.uniq
  end

  def parse
    parser = Rogdl::Parser.new
    parser.translate(contents)
    parser.lines.reject { |line| line.empty? }
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
bibliothecary-0.14.1 lib/cartfile_parser.rb
bibliothecary-0.14.0 lib/cartfile_parser.rb
bibliothecary-0.13.1 lib/cartfile_parser.rb
bibliothecary-0.13.0 lib/cartfile_parser.rb
bibliothecary-0.12.0 lib/cartfile_parser.rb
bibliothecary-0.11.0 lib/cartfile_parser.rb
bibliothecary-0.10.0 lib/cartfile_parser.rb
bibliothecary-0.9.0 lib/cartfile_parser.rb
bibliothecary-0.8.0 lib/cartfile_parser.rb
bibliothecary-0.7.1 lib/cartfile_parser.rb
bibliothecary-0.7.0 lib/cartfile_parser.rb
bibliothecary-0.6.0 lib/cartfile_parser.rb
bibliothecary-0.5.0 lib/cartfile_parser.rb
bibliothecary-0.4.1 lib/cartfile_parser.rb
bibliothecary-0.4.0 lib/cartfile_parser.rb