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.39 lib/vedeu/models/row.rb
vedeu-0.6.38 lib/vedeu/models/row.rb
vedeu-0.6.37 lib/vedeu/models/row.rb
vedeu-0.6.36 lib/vedeu/models/row.rb
vedeu-0.6.35 lib/vedeu/models/row.rb
vedeu-0.6.34 lib/vedeu/models/row.rb
vedeu-0.6.33 lib/vedeu/models/row.rb
vedeu-0.6.32 lib/vedeu/models/row.rb
vedeu-0.6.31 lib/vedeu/models/row.rb
vedeu-0.6.30 lib/vedeu/models/row.rb
vedeu-0.6.29 lib/vedeu/models/row.rb
vedeu-0.6.28 lib/vedeu/models/row.rb
vedeu-0.6.27 lib/vedeu/models/row.rb
vedeu-0.6.26 lib/vedeu/models/row.rb
vedeu-0.6.25 lib/vedeu/models/row.rb
vedeu-0.6.24 lib/vedeu/models/row.rb
vedeu-0.6.23 lib/vedeu/models/row.rb
vedeu-0.6.22 lib/vedeu/models/row.rb
vedeu-0.6.21 lib/vedeu/models/row.rb
vedeu-0.6.20 lib/vedeu/models/row.rb