Sha256: 7579ce999d292ed9dd080ddee902b7d4fa1e0fd9dfd0836be7d86def56aebac2

Contents?: true

Size: 695 Bytes

Versions: 9

Compression:

Stored size: 695 Bytes

Contents

module TrelloFlow
  class Table
    class Row
      attr_reader :num

      def initialize(record, index)
        @record = record
        @num = index + 1
      end

      def to_h
        result = { "#": @num }
        fields.each do |field|
          result[field] = colorize(@record.send(field))
        end
        result
      end

      private

        def colorize(str)
          return str unless str.respond_to?(color)
          str.send(color)
        end

        def color
          custom_color = @record.color if @record.respond_to?(:color)
          custom_color || :white
        end

        def fields
          @fields ||= @record.class.fields
        end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
trello_flow-2.1.0 lib/trello_flow/table/row.rb
trello_flow-2.0.1 lib/trello_flow/table/row.rb
trello_flow-2.0.0 lib/trello_flow/table/row.rb
trello_flow-1.3.0 lib/trello_flow/table/row.rb
trello_flow-1.2.2 lib/trello_flow/table/row.rb
trello_flow-1.2.1 lib/trello_flow/table/row.rb
trello_flow-1.2.0 lib/trello_flow/table/row.rb
trello_flow-1.1.0 lib/trello_flow/table/row.rb
trello_flow-1.0.1 lib/trello_flow/table/row.rb