Module: Squib
- Defined in:
- lib/squib_plus/pdf.rb,
lib/squib_plus/deck.rb,
lib/squib_plus/subset.rb,
lib/squib_plus/card_size.rb,
lib/squib_plus/deck/avatar.rb,
lib/squib_plus/google_sheets.rb
Defined Under Namespace
Constant Summary collapse
- @@card_sizes =
{ bridge: { width: '2.5in', height: '3.75in' }, business: { width: '2.25in', height: '3.75in' }, divider: { width: '3.25in', height: '3.75in' }, domino: { width: '2in', height: '3.75in' }, euro_poker: { width: '2.73in', height: '3.71in' }, euro_square: { width: '3.01in', height: '3.01in' }, jumbo: { width: '3.75in', height: '5.75in' }, micro: { width: '1.5in', height: '2in' }, mini: { width: '2in', height: '2.75in' }, poker: { width: '2.75in', height: '3.75in' }, mint_tin: { width: '2.3in', height: '3.71in' }, small_square: { width: '2.75in', height: '2.75in' }, square: { width: '3.75in', height: '3.75in' }, tarot: { width: '2.75in', height: '5in' }, us_game: { width: '2.45in', height: '3.68in' } }
Class Method Summary collapse
- .card_size(name, landscape: false) ⇒ Object
-
.combine_pdfs(sheets, file) ⇒ Object
# Combine PnP Squib.combine_pdfs([ { :front => “_output/front.pdf”, :back => “_output/back.pdf” }, ], “_output/pnp.pdf”).
-
.gsheet(sheet_id, index = 0) ⇒ Object
gsheet allows you to load Deck data using Google Sheets.
-
.subset(column, criteria, matching: true) ⇒ Object
Subset a selection of cards based on some criteria.
Class Method Details
.card_size(name, landscape: false) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/squib_plus/card_size.rb', line 28 def card_size(name, landscape: false) dimensions = @@card_sizes.fetch name dimensions = { width: dimensions[:height], height: dimensions[:width] } if landscape { dpi: 300 }.merge dimensions end |
.combine_pdfs(sheets, file) ⇒ Object
# Combine PnP
Squib.combine_pdfs([
{ :front => "_output/front.pdf", :back => "_output/back.pdf" },
], "_output/pnp.pdf")
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/squib_plus/pdf.rb', line 26 def combine_pdfs(sheets, file) pdf = CombinePDF.new sheets.each do |sheet| front = CombinePDF.load(sheet[:front]) # Collate the back pages immediately after the relevant page, # if a back-side is provided. back = CombinePDF.load(sheet[:back]) if sheet.key?(:back) i = 0 front.pages.each do |page| pdf << page pdf << back.pages[i] if sheet.key?(:back) break if i == front.pages.count - 1 i += 1 end end pdf.save file end |
.gsheet(sheet_id, index = 0) ⇒ Object
gsheet allows you to load Deck data using Google Sheets.
First, share your sheet using File > Publish to the web Select ‘Entire document’ and ‘.csv’ as the format Copy the URL like
https://docs.google.com/spreadsheets/d/e/2PACX-.../pub?output=csv
^^^^^^^^^
The code you need to pass is the long ID after /d/e.
If the sheet has multiple tabs, you can specify a later tab using the gid from the non-share URL like
https://docs.google.com/spreadsheets/d/.../edit#gid=123456
^^^^^^
The gid is at the end of the URL after #gid=
Example:
deck = Squib.gsheet('2PACX-...', 123456)
Squib::Deck.new(cards: deck['name'].size) do
...
end
You can optionally specify the tab to use with the second argument
29 30 31 32 33 34 35 |
# File 'lib/squib_plus/google_sheets.rb', line 29 def gsheet(sheet_id, index = 0) agent = Mechanize.new response = agent.get_file("https://docs.google.com/spreadsheets/d/e/#{sheet_id}/pub?gid=#{index}&output=csv") response = response.encode('ascii-8bit').force_encoding('utf-8') Squib.csv data: response end |
.subset(column, criteria, matching: true) ⇒ Object
Subset a selection of cards based on some criteria. Can be passed directly into the range argument of other DSL functions.
Example:
gems = Squib.subset(deck['category'], -> (c) { c === 'gem' })
text range: gems, str: deck['gem_num'], layout: 'gem_label'
You can invert the match using matching: false This allows you to use a single criteria function for positive/negative matches.
14 15 16 17 18 19 |
# File 'lib/squib_plus/subset.rb', line 14 def subset(column, criteria, matching: true) sub = {} column.each_with_index { |c, i| (sub[criteria.call(c)] ||= []) << i } sub[matching] end |