module Terjira::CommonPresenter

Public Instance Methods

dim_none() click to toggle source
# File lib/terjira/presenters/common_presenter.rb, line 22
def dim_none
  dim('None')
end
formatted_date(date_str, date_format = '%c') click to toggle source
# File lib/terjira/presenters/common_presenter.rb, line 26
def formatted_date(date_str, date_format = '%c')
  return nil if date_str.nil? || date_str.empty?
  Time.parse(date_str).strftime(date_format)
end
insert_new_line(str, length) click to toggle source

Insert new line(`n`) when string display length is longger than length argument

# File lib/terjira/presenters/common_presenter.rb, line 49
def insert_new_line(str, length)
  str.split(/\r\n|\n/).map do |line|
    line.strip!
    if line.display_width < 1
      line
    else
      display_length = pastel.strip(line).display_width
      split_length = (line.length * length / display_length).to_i
      line.scan(/.{1,#{split_length}}/).join("\n") rescue line
    end
  end.join("\n")
end
pastel() click to toggle source
# File lib/terjira/presenters/common_presenter.rb, line 18
def pastel
  @pastel ||= Pastel.new
end
render(text) click to toggle source
# File lib/terjira/presenters/common_presenter.rb, line 10
def render(text)
  if text.is_a? Array
    puts text.join("\n")
  else
    puts text
  end
end
screen_width() click to toggle source
# File lib/terjira/presenters/common_presenter.rb, line 43
def screen_width
  TTY::Screen.width
end
username(user) click to toggle source
# File lib/terjira/presenters/common_presenter.rb, line 31
def username(user)
  if user.nil?
    dim_none
  else
    begin
      "#{user.displayName} (#{user.name})"
    rescue NoMethodError
      user.displayName.to_s
    end
  end
end