Sha256: e54145fc3565ef5007f4aec8f48f3083ecf3e89f702cf59831ffc25c46f2ad74

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

require 'iconv' unless "older_ruby?".respond_to?(:force_encoding)

module PT
  class DataRow

    attr_accessor :num, :record, :state, :owners

    def initialize(orig, dataset)
      @record = orig
      @num = dataset.index(orig) + 1
      if defined? orig.current_state
        @state = orig.current_state
      end
    end

    def method_missing(method)
      str = @record.send(method).to_s
      str.respond_to?(:force_encoding) ? str.force_encoding('utf-8') : Iconv.iconv('UTF-8', 'UTF-8', str)
    end

    def to_s
      @record.send(self.to_s_attribute)
    end

    def to_s_attribute
      @n.to_s
    end

    def name
      _name = @record.name
      if _name.size > 15
        _name[0..15] + '...'
      else
        _name
      end
    end

    def owners
      if @record.instance_variable_get(:@owners).present?
        @record.owners.map{|o| o.initials == Settings[:user_initials] ? o.initials.red : o.initials }.join(',')
      end
    end

    def state
      state = @record.current_state
      case state
      when 'delivered'
        state.yellow
      when 'finished'
        state.blue
      when 'accepted'
        state.green
      when 'rejected'
        state.red
      when 'started'
        state.white
      else
        state.black
      end
    end

    def story_type
      t = @record.story_type
      case t
      when 'bug'
        '🐞'
      when 'feature'
        '⭐'
      when 'release'
        '🏁'
      when 'chore'
        '⚙️'
      else
        t
      end
    end

    def estimate
      @record.estimate.to_i if @record.estimate
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ipt-1.0.1 lib/pt/data_row.rb
ipt-1.0.0 lib/pt/data_row.rb