Sha256: 7d534060c257bd55f703ba08e79739813347ae59da4a9b72c5092fecc54e7407

Contents?: true

Size: 871 Bytes

Versions: 2

Compression:

Stored size: 871 Bytes

Contents

module ConfCtl
  class Swpins::ChannelList < Array
    # @return [Swpins::ChannelList]
    def self.get
      @get ||= new
    end

    # @param pattern [String]
    def self.pattern(pattern)
      get.pattern(pattern)
    end

    def self.refresh
      get.refresh
    end

    # @param pattern [String]
    def initialize(pattern: '*')
      super()
      parse(pattern:)
    end

    # @param pattern [String]
    # @return [Array<Swpins::Channel>]
    def pattern(pattern)
      select { |c| Pattern.match?(pattern, c.name) }
    end

    def refresh
      clear
      parse
    end

    protected

    def parse(pattern: '*')
      nix = Nix.new
      nix.list_swpins_channels.each do |name, nix_specs|
        next unless Pattern.match?(pattern, name)

        c = Swpins::Channel.new(name, nix_specs)
        c.parse
        self << c
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
confctl-2.0.0 lib/confctl/swpins/channel_list.rb
confctl-1.0.0 lib/confctl/swpins/channel_list.rb