Sha256: 91a0191e97ef74632ae69f02997f7559436307e83b9af5c5ef0cd412a4edfbb2

Contents?: true

Size: 1.89 KB

Versions: 4

Compression:

Stored size: 1.89 KB

Contents

module Net

  class NNTP

    class Group
      attr_reader :name, :article_count, :article_first, :article_last
      attr_reader :hi, :lo, :postingmode

      def initialize(name)
        @name = name
        @articles ||= Articles.new(self)
        #@articles.group = self
        @article_first = @article_last = @article_count = nil
      end

      # Set article_count, article_first, article_last (from GROUP command)
      #
      # Takes an array [count, first, last] as argument
      def article_info=(art_array)
        @article_count = art_array[0].to_i
        @article_first = art_array[1].to_i
        @article_last = art_array[2].to_i
      end

      def articles
        @articles
      end

      def articles=(articles)
        @articles = articles
      end

      # Sets hi and lo watermark alont with postingmode (from LIST ACTIVE command)
      def listinfo(hi, lo, postingmode)
        @hi = hi
        @lo = lo
        @postingmode = postingmode
      end

      def inspect
"Group: #{@name}  #{@article_count} #{@article_first} #{@article_last}"
      end

      class Articles

        attr_accessor :group

        def initialize(group)
          @articles ||=[]
        end

        # Stores articles in group attribute, using Net::NNTP::Article instances
        def build_from_over(over, format)
          article = Article.new
          article.overview_format = format
          article.overview(over)
          @articles << article
        end

        def length
          @articles.length
        end

        def <<(article)
          @articles << article
        end

        # Creates one Net::NNTP::Article instance, sets the group attribute to the
        # including group instances and adds the article to articles before returning it
        def create
          a = Article.new
          a.group = self.group
          @articles << a
          a
        end

      end

    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-net-nntp-0.1.0 lib/net/nntp/group.rb
ruby-net-nntp-0.2.1 lib/net/nntp/group.rb
ruby-net-nntp-0.2.2 lib/net/nntp/group.rb
ruby-net-nntp-0.2.0 lib/net/nntp/group.rb