Module: Indirect
- Defined in:
- lib/indirect.rb,
lib/indirect/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"1.2.0"
Class Method Summary collapse
Class Method Details
.card_path ⇒ Object
107 108 109 |
# File 'lib/indirect.rb', line 107 def self.card_path File.("output", __dir__) end |
.generate_card ⇒ Object
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/indirect.rb', line 40 def self.generate_card require "colorize" colors = [:cyan, :green, :blue, :magenta].cycle title = [info.name, "/".green, info.handle].join(" ") job = { "Work" => info.job, "" => "https://" << info.job_website.send(colors.next), }.select{|k,v| v } oss = { "Open Source" => info.oss, "" => "https://" << info.oss_website.send(colors.next), }.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, "Bluesky" => info.bluesky ? "https://bsky.app/profile/" << info.bluesky.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 " << info.card.send(colors.next) : nil }.select{|k,v| v } sections = [job, oss, 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 << (name.empty? ? " " : ": ") [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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/indirect.rb', line 86 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 |
.info ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/indirect.rb', line 16 def self.info Info.new( name: "André Arko", handle: "@indirect", job: "Founder at Spinel Cooperative", job_website: "spinel.coop", oss: "Member at The Gem Cooperative", oss_website: "gem.coop", email: "[email protected]", website: "arko.net", blog: "andre.arko.net", bluesky: "@indirect.io", github: "indirect", linkedin: "andrearko", mastodon: "fiasco.social/@indirect", card: "indirect", ) end |
.run ⇒ Object
35 36 37 38 |
# File 'lib/indirect.rb', line 35 def self.run generate_card unless File.exist?(card_path) puts File.read(card_path) end |