Skip to content

Instantly share code, notes, and snippets.

@andymeneely
Created February 7, 2017 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymeneely/039b5d8aa9d973dd488aac6c984eb1e3 to your computer and use it in GitHub Desktop.
Save andymeneely/039b5d8aa9d973dd488aac6c984eb1e3 to your computer and use it in GitHub Desktop.
Squib example for referencing other cards
require 'squib'
# This makes use of Ruby's heredoc - it's just a string
data = Squib.csv data:(<<-CSV)
Name,Cost,Friend
Stringer,3,Avon
Avon,2,Stringer
CSV
Squib::Deck.new(cards: data.nrows, width: 300, height: 300) do
background color: :white
rect #black border lines
text str: data['Name'] # Title at the top
text str: data['Cost'], x: 250 # Cost at the top
# Map Name back to index - future-friendly for data changes
# This example: { 'Stringer' => 0, 'Avon' => 1 }
idx = {} ; data['Name'].each_with_index{ |name, i| idx[name] = i}
text str: 'Difference in cost from friend', font_size: 15, y: 100
friends = data['Friend'].map.with_index do |friend, i|
my_cost = data['Cost'][i]
friend_cost = data['Cost'][idx[friend]] #look up the reference
my_cost - friend_cost
end
text str: friends, y: 150
save_sheet prefix: 'sheet_'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment