Sha256: ee3813e972602ab81b35e1b71b39207c3302dcf30739c2ae683cb7074ee1c3a6

Contents?: true

Size: 886 Bytes

Versions: 13

Compression:

Stored size: 886 Bytes

Contents

module TrelloFlow
  class Table
    class Row
      attr_reader :num

      COLOR_TRANSLATIONS = {
        "purple" => "magenta",
        "orange" => "yellow",
        "sky" => "cyan",
        "pink" => "red",
        "lime" => "green"
      }

      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

        attr_reader :num, :record

        def colorize(str)
          return str unless record.respond_to?(:color)
          "■".send(color) + " #{str}"
        end

        def color
          COLOR_TRANSLATIONS[record.color] || record.color || :white
        end

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
trello_flow-3.8.0 lib/trello_flow/table/row.rb
trello_flow-3.7.1 lib/trello_flow/table/row.rb
trello_flow-3.7.0 lib/trello_flow/table/row.rb
trello_flow-3.6.0 lib/trello_flow/table/row.rb
trello_flow-3.5.0 lib/trello_flow/table/row.rb
trello_flow-3.4.0 lib/trello_flow/table/row.rb
trello_flow-3.3.0 lib/trello_flow/table/row.rb
trello_flow-3.1.0 lib/trello_flow/table/row.rb
trello_flow-3.0.0 lib/trello_flow/table/row.rb
trello_flow-2.3.1 lib/trello_flow/table/row.rb
trello_flow-2.3.0 lib/trello_flow/table/row.rb
trello_flow-2.2.1 lib/trello_flow/table/row.rb
trello_flow-2.2.0 lib/trello_flow/table/row.rb