Module: Indirect

Defined in:
lib/indirect.rb,
lib/indirect/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"1.1.0"

Class Method Summary collapse

Class Method Details

.card_pathObject



90
91
92
# File 'lib/indirect.rb', line 90

def self.card_path
  File.expand_path("output", __dir__)
end

.generate_cardObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/indirect.rb', line 29

def self.generate_card
  require "colorize"
  colors = [:cyan, :red, :blue, :green].cycle

  title = [info.name.white, "/".green, info.handle.white].join(" ")

  work = {
    "Work" => info.job.white,
    "Open Source" => info.oss.white,
  }.select{|k,v| v }

  contact = {
    "Email" => info.email ? info.email.send(colors.next) : nil,
    "Website" => info.website ? "https://" << info.website.send(colors.next) : nil,
    "Blog" => info.blog ? "https://" << info.blog.send(colors.next) : nil,
    "GitHub" => info.github ? "https://github.com/" << info.github.send(colors.next) : nil,
    "Mastodon" => info.twitter ? "https://" << info.mastodon.send(colors.next) : nil,
    "Twitter" => info.twitter ? "https://twitter.com/" << info.twitter.send(colors.next) : nil,
    "LinkedIn" => info.linkedin ? "https://linkedin.com/in/" << info.linkedin.send(colors.next) : nil,
  }.select{|k,v| v }

  card = {
    "Card" => info.card ? "gem exec ".red << info.card.white : nil
  }.select{|k,v| v }

  sections = [work, contact, card]
  label_size = sections.map(&:keys).flatten.map(&:length).max

  body = sections.map do |section|
    section.map do |name, value|
      label = sprintf("%#{label_size}s", name) << ": "
      [label.white.bold, value].join
    end.join("\n")
  end.join("\n\n")

  content = [title, body].join("\n\n")

  File.write card_path, in_box(content)
end

.in_box(content) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/indirect.rb', line 69

def self.in_box(content)
  require "colorize"
  width = content.lines.map(&:uncolorize).map(&:length).max
  edge_size = width + 6

  box = "" << "" * edge_size << "╮\n"
  box << "" << " " * edge_size << "│\n"

  title = content.lines.first
  cc = (width - title.chomp.uncolorize.size) / 2
  box << "" << " " * cc << title.chomp << " " * cc << "    │\n"

  content.lines[1..-1].each do |line|
    space_count = width - line.chomp.uncolorize.size
    box << "" << line.chomp << " " * space_count << "   │\n"
  end

  box << "" << " " * edge_size << "│\n"
  box << "" << "" * edge_size << ""
end

.infoObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/indirect.rb', line 7

def self.info
  OpenStruct.new(
    name: "André Arko",
    handle: "indirect",
    job: "Vice Minister of Computation at cloudcity.io",
    oss: "RubyGems Coordinator at Ruby Central",
    email: "[email protected]",
    website: "arko.net",
    blog: "andre.arko.net",
    twitter: "indirect",
    github: "indirect",
    linkedin: "andrearko",
    mastodon: "fiasco.social/@indirect",
    card: "indirect",
  )
end

.runObject



24
25
26
27
# File 'lib/indirect.rb', line 24

def self.run
  generate_card unless File.exist?(card_path)
  puts File.read(card_path)
end