Sha256: 2b0d55188d29b844ac5341ff22f8db166810d0b58d7fdd4e87e35945683522ea

Contents?: true

Size: 740 Bytes

Versions: 12

Compression:

Stored size: 740 Bytes

Contents

module Gdshowsdb
  class Diff
    def initialize(from_yaml, from_db)
      @from_yaml = from_yaml
      @yaml_uuids = extract_uuids(@from_yaml)
      @from_db = from_db
      @db_uuids = extract_uuids(@from_db)
    end

    def added
      (@from_yaml - @from_db).reject do |item|
        @db_uuids.member?(item[:uuid])
      end
    end

    def removed
      (@from_db - @from_yaml).reject do |item|
        @yaml_uuids.member?(item[:uuid])
      end
    end

    def updated
      (@from_yaml - @from_db).select do |item|
        @yaml_uuids.member?(item[:uuid]) && @db_uuids.member?(item[:uuid])
      end
    end

    private

    def extract_uuids(hashes)
      hashes.map do |hash|
        hash[:uuid]
      end
    end    
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gdshowsdb-4.0.2 lib/gdshowsdb/diff.rb
gdshowsdb-4.0.1 lib/gdshowsdb/diff.rb
gdshowsdb-4.0.0 lib/gdshowsdb/diff.rb
gdshowsdb-3.0.0 lib/gdshowsdb/diff.rb
gdshowsdb-2.1.0 lib/gdshowsdb/diff.rb
gdshowsdb-2.0.0 lib/gdshowsdb/diff.rb
gdshowsdb-1.0.3 lib/gdshowsdb/diff.rb
gdshowsdb-1.0.2 lib/gdshowsdb/diff.rb
gdshowsdb-1.0.1 lib/gdshowsdb/diff.rb
gdshowsdb-1.0.0 lib/gdshowsdb/diff.rb
gdshowsdb-0.9.1 lib/gdshowsdb/diff.rb
gdshowsdb-0.9.0 lib/gdshowsdb/diff.rb