Sha256: 73883d3f06aa4615749bb88402cc18131630c065ac3c4a92571c1f9063c14d16

Contents?: true

Size: 1.49 KB

Versions: 11

Compression:

Stored size: 1.49 KB

Contents

# Reads in a DBF file and creates items out of them, annotating with information from CUTS
module DubbletrackRemote
  module Reader
    def self.new(file_path, options = {})
      if File.extname(file_path) == ".DBF"
        DubbletrackRemote::Reader::DBF.new(file_path, options)
      elsif File.extname(file_path) == ".TSV"
        DubbletrackRemote::Reader::TSV.new(file_path, options)
      end
    end

    def self.watch(playlist_path, options = {}, &block)
      pattern = options[:pattern] || Regexp.new(".+")
      listener = Listen.to(playlist_path, force_polling: true, wait_for_delay: 4) do |modified, added|
        [modified, added].flatten.compact.uniq.each do |file|
          if pattern.match(file)
            block.call(file)
          end
        end
      rescue => e
        puts "errored while listening for changes, will continue listening"
        puts e
      end

      listener.start
    end

    class Base
      attr_reader :use_database

      def items
        @items ||= read_items.sort_by(&:played_at)
      end

      def tracks
        items.select { |i| i.item_type == DubbletrackRemote::Item::TRACK }
      end

      def traffic
        items.select { |i| i.item_type == DubbletrackRemote::Item::TRAFFIC }
      end

      def ingest
        items.select { |s| s.changed? || s.new_record? }.each do |item|
          puts item.to_json
          item.save
        end

        items
      end

      def read_items
        raise "must implement in subclass"
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dubbletrack_remote-0.8.4 lib/dubbletrack_remote/reader/base.rb
dubbletrack_remote-0.8.3 lib/dubbletrack_remote/reader/base.rb
dubbletrack_remote-0.8.2 lib/dubbletrack_remote/reader/base.rb
dubbletrack_remote-0.8.1 lib/dubbletrack_remote/reader/base.rb
dubbletrack_remote-0.8.0 lib/dubbletrack_remote/reader/base.rb
dubbletrack_remote-0.7.6 lib/dubbletrack_remote/reader/base.rb
dubbletrack_remote-0.7.5 lib/dubbletrack_remote/reader/base.rb
dubbletrack_remote-0.7.4 lib/dubbletrack_remote/reader/base.rb
dubbletrack_remote-0.7.3 lib/dubbletrack_remote/reader/base.rb
dubbletrack_remote-0.7.2 lib/dubbletrack_remote/reader/base.rb
dubbletrack_remote-0.7.1 lib/dubbletrack_remote/reader/base.rb