Sha256: f635126266170c2d452945de0236bc69e8fada1d9eb49bd2ada32a8b3d5deff4

Contents?: true

Size: 1.52 KB

Versions: 50

Compression:

Stored size: 1.52 KB

Contents

module Vedeu

  module Models

    # A Row represents an array of Vedeu::Models::Cell objects.
    #
    class Row

      include Enumerable

      # @!attribute [r] cells
      # @return [Array<NilClass|void>]
      attr_reader :cells

      # @param value [Vedeu::Models::Row|Array<void>|void]
      # @return [Vedeu::Models::Row]
      def self.coerce(value)
        if value.is_a?(self)
          value

        elsif value.is_a?(Array)
          new(value.compact)

        elsif value.nil?
          new

        else
          new([value])

        end
      end

      # Returns an instance of Vedeu::Models::Row.
      #
      # @param cells [Array<NilClass|void>]
      # @return [Vedeu::Models::Row]
      def initialize(cells = [])
        @cells = cells || []
      end

      # @param index [Fixnum]
      # @return [NilClass|void]
      def cell(index)
        return nil if index.nil?

        cells[index]
      end

      # @return [Array<void>]
      def content
        cells.flatten
      end

      # Provides iteration over the collection.
      #
      # @param block [Proc]
      # @return [Enumerator]
      def each(&block)
        cells.each(&block)
      end

      # @return [Boolean]
      def empty?
        cells.empty?
      end

      # An object is equal when its values are the same.
      #
      # @param other [Vedeu::Models::Row]
      # @return [Boolean]
      def eql?(other)
        self.class == other.class && cells == other.cells
      end
      alias_method :==, :eql?

    end # Row

  end # Models

end # Vedeu

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
vedeu-0.6.60 lib/vedeu/models/row.rb
vedeu-0.6.59 lib/vedeu/models/row.rb
vedeu-0.6.58 lib/vedeu/models/row.rb
vedeu-0.6.57 lib/vedeu/models/row.rb
vedeu-0.6.56 lib/vedeu/models/row.rb
vedeu-0.6.54 lib/vedeu/models/row.rb
vedeu-0.6.53 lib/vedeu/models/row.rb
vedeu-0.6.52 lib/vedeu/models/row.rb
vedeu-0.6.51 lib/vedeu/models/row.rb
vedeu-0.6.50 lib/vedeu/models/row.rb
vedeu-0.6.49 lib/vedeu/models/row.rb
vedeu-0.6.48 lib/vedeu/models/row.rb
vedeu-0.6.47 lib/vedeu/models/row.rb
vedeu-0.6.46 lib/vedeu/models/row.rb
vedeu-0.6.45 lib/vedeu/models/row.rb
vedeu-0.6.44 lib/vedeu/models/row.rb
vedeu-0.6.43 lib/vedeu/models/row.rb
vedeu-0.6.42 lib/vedeu/models/row.rb
vedeu-0.6.41 lib/vedeu/models/row.rb
vedeu-0.6.40 lib/vedeu/models/row.rb