Module: Tr3llo::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/3llo/utils.rb

Constant Summary collapse

COLOR =
{
  "red" => 31,
  "pink" => 31,
  "blue" => 34,
  "green" => 32,
  "lime" => 32,
  "black" => 37,
  "white" => 37,
  "purple" => 35,
  "yellow" => 33,
  "orange" => 33,
  "cyan" => 36,
  "sky" => 36
}.freeze()
TRELLO_LABEL_COLOR =
%w[red pink blue green purple yellow orange sky].freeze()

Instance Method Summary collapse

Instance Method Details

#assert_string!(data, message) ⇒ Object



29
30
31
# File 'lib/3llo/utils.rb', line 29

def assert_string!(data, message)
  raise InvalidArgumentError.new(message) unless data.is_a?(String)
end

#build_req_path(path, extra_params = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/3llo/utils.rb', line 61

def build_req_path(path, extra_params = {})
  params =
    {
      "key" => Application.fetch_configuration!().api_key,
      "token" => Application.fetch_configuration!().api_token
    }.merge(extra_params)

  [path, URI.encode_www_form(params)].join("?")
end

#deprecate!(message) ⇒ Object



37
38
39
40
41
# File 'lib/3llo/utils.rb', line 37

def deprecate!(message)
  interface = Application.fetch_interface!()

  interface.puts(Utils.paint("DEPRECATED: #{message}", "yellow"))
end

#format_bold(string) ⇒ Object



49
50
51
# File 'lib/3llo/utils.rb', line 49

def format_bold(string)
  "\e[1m#{string}\e[0m"
end

#format_dim(string) ⇒ Object



53
54
55
# File 'lib/3llo/utils.rb', line 53

def format_dim(string)
  "\e[2m#{string}\e[0m"
end

#format_highlight(string) ⇒ Object



57
58
59
# File 'lib/3llo/utils.rb', line 57

def format_highlight(string)
  paint(string, "yellow")
end

#format_key_tag(id, shortcut) ⇒ Object



22
23
24
25
26
27
# File 'lib/3llo/utils.rb', line 22

def format_key_tag(id, shortcut)
  formatted_shortcut = Utils.format_highlight(Entities::SHORTCUT_PREFIX + shortcut)
  formatted_id = Utils.paint(id, "blue")

  "[#{formatted_id} #{formatted_shortcut}]"
end

#format_user(user) ⇒ Object



33
34
35
# File 'lib/3llo/utils.rb', line 33

def format_user(user)
  Utils.paint("@" + user.username, "blue")
end

#paint(string, color) ⇒ Object



43
44
45
46
47
# File 'lib/3llo/utils.rb', line 43

def paint(string, color)
  code = COLOR.fetch(color)

  "\e[#{code}m#{string}\e[0m"
end

#require_directory(glob) ⇒ Object



71
72
73
74
75
# File 'lib/3llo/utils.rb', line 71

def require_directory(glob)
  Dir.glob(glob).each do |file|
    require file
  end
end