Module: Squib
- Defined in:
- lib/squib/deck.rb,
lib/squib.rb,
lib/squib/card.rb,
lib/squib/conf.rb,
lib/squib/version.rb,
lib/squib/api/data.rb,
lib/squib/api/save.rb,
lib/squib/api/text.rb,
lib/squib/args/box.rb,
lib/squib/progress.rb,
lib/squib/api/image.rb,
lib/squib/api/units.rb,
lib/squib/args/draw.rb,
lib/squib/constants.rb,
lib/squib/api/groups.rb,
lib/squib/api/shapes.rb,
lib/squib/args/paint.rb,
lib/squib/args/sheet.rb,
lib/squib/args/coords.rb,
lib/squib/args/import.rb,
lib/squib/api/settings.rb,
lib/squib/commands/cli.rb,
lib/squib/commands/new.rb,
lib/squib/sprues/sprue.rb,
lib/squib/args/csv_opts.rb,
lib/squib/graphics/hand.rb,
lib/squib/graphics/text.rb,
lib/squib/layout_parser.rb,
lib/squib/api/background.rb,
lib/squib/api/text_embed.rb,
lib/squib/args/embed_key.rb,
lib/squib/args/paragraph.rb,
lib/squib/args/scale_box.rb,
lib/squib/args/transform.rb,
lib/squib/graphics/image.rb,
lib/squib/sample_helpers.rb,
lib/squib/args/arg_loader.rb,
lib/squib/args/card_range.rb,
lib/squib/args/input_file.rb,
lib/squib/args/save_batch.rb,
lib/squib/args/sprue_file.rb,
lib/squib/graphics/shapes.rb,
lib/squib/args/svg_special.rb,
lib/squib/args/typographer.rb,
lib/squib/sprues/crop_line.rb,
lib/squib/args/embed_adjust.rb,
lib/squib/args/hand_special.rb,
lib/squib/graphics/save_doc.rb,
lib/squib/graphics/save_pdf.rb,
lib/squib/graphics/showcase.rb,
lib/squib/import/data_frame.rb,
lib/squib/args/dir_validator.rb,
lib/squib/commands/make_sprue.rb,
lib/squib/graphics/background.rb,
lib/squib/graphics/save_sprue.rb,
lib/squib/sprues/sprue_schema.rb,
lib/squib/args/color_validator.rb,
lib/squib/args/unit_conversion.rb,
lib/squib/graphics/save_images.rb,
lib/squib/args/showcase_special.rb,
lib/squib/sprues/crop_line_dash.rb,
lib/squib/graphics/gradient_regex.rb,
lib/squib/graphics/embedding_utils.rb,
lib/squib/commands/data/template_option.rb,
lib/squib/graphics/cairo_context_wrapper.rb,
lib/squib/sprues/invalid_sprue_definition.rb
Overview
The project module
Defined Under Namespace
Modules: Args, Commands, Graphics, Sprues Classes: CLI, Card, Conf, DataFrame, Deck, DoNothing, EmbeddingUtils, Gap, LayoutParser, Margin, Progress, Sprue, TemplateOption, TextEmbed
Constant Summary collapse
- USER_CONFIG =
{}
- VERSION =
The next version to be released. Uses semantic versioning: semver.org/
Most of the time this is in the alpha of the next release. e.g. v0.0.5a is on its way to becoming v0.0.5
'0.14.2'
- DEFAULT_FONT =
System-wide default font :nodoc:
'Arial 12'
- INCHES_IN_CM =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Used for inch-cm conversion :nodoc:
0.393700787
- POINTS_PER_IN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Used for points-inch conversion :nodoc:
72.0
Class Method Summary collapse
-
.cache_load_image(file) ⇒ Object
private
Cache all pngs we’ve already loaded.
-
.check_duplicate_csv_headers(table) ⇒ Object
private
Check if the given CSV table has duplicate columns, and throw a warning.
- .configure(opts) ⇒ Object
-
.csv(opts = {}) ⇒ Object
DSL method.
-
.disable_build_globally(group) ⇒ Object
DSL method.
-
.enable_build_globally(group) ⇒ Object
DSL method.
- .explode_quantities(data, qty) ⇒ Object private
-
.logger ⇒ Logger
Access the internal logger that Squib uses.
-
.xlsx(opts = {}) ⇒ Object
DSL method.
-
.yaml(opts = {}) ⇒ Object
DSL method.
Class Method Details
.cache_load_image(file) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Cache all pngs we’ve already loaded
:nodoc:
7 8 9 10 |
# File 'lib/squib/graphics/image.rb', line 7 def cache_load_image(file) @img_cache ||= {} @img_cache[file] || @img_cache[file] = Cairo::ImageSurface.from_png(file) end |
.check_duplicate_csv_headers(table) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if the given CSV table has duplicate columns, and throw a warning
97 98 99 100 101 102 |
# File 'lib/squib/api/data.rb', line 97 def check_duplicate_csv_headers(table) if table.headers.size != table.headers.uniq.size dups = table.headers.select{|e| table.headers.count(e) > 1 } Squib.logger.warn "CSV duplicated the following column keys: #{dups.join(',')}" end end |
.configure(opts) ⇒ Object
8 9 10 11 |
# File 'lib/squib/conf.rb', line 8 def configure(opts) str_hash = opts.inject({}) { |h, (k, v)| h[k.to_s] = v; h } USER_CONFIG.merge! str_hash end |
.csv(opts = {}) ⇒ Object
DSL method. See squib.readthedocs.io
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 68 |
# File 'lib/squib/api/data.rb', line 36 def csv(opts = {}) # TODO refactor all this out to separate methods, and its own class import = Args::Import.new.load!(opts) file = Args::InputFile.new(file: 'deck.csv').load!(opts).file[0] data = opts.key?(:data) ? opts[:data] : File.read(file) csv_opts = Args::CSV_Opts.new(opts) table = CSV.parse(data, csv_opts.to_hash) check_duplicate_csv_headers(table) hash = Squib::DataFrame.new table.headers.each do |header| new_header = header.to_s new_header = new_header.strip if import.strip? hash[new_header] ||= table[header] end if import.strip? new_hash = Squib::DataFrame.new hash.each do |header, col| new_hash[header] = col.map do |str| str = str.strip if str.respond_to?(:strip) str end end hash = new_hash end if block_given? hash.each do |header, col| col.map! do |val| yield(header, val) end end end return explode_quantities(hash, import.explode) end |
.disable_build_globally(group) ⇒ Object
DSL method. See squib.readthedocs.io
13 14 15 16 17 |
# File 'lib/squib/api/groups.rb', line 13 def disable_build_globally group groups = (ENV['SQUIB_BUILD'] ||= '').split(',') groups.delete(group.to_s) ENV['SQUIB_BUILD'] = groups.uniq.join(',') end |
.enable_build_globally(group) ⇒ Object
DSL method. See squib.readthedocs.io
6 7 8 9 |
# File 'lib/squib/api/groups.rb', line 6 def enable_build_globally group groups = (ENV['SQUIB_BUILD'] ||= '').split(',') ENV['SQUIB_BUILD'] = (groups << group).uniq.join(',') end |
.explode_quantities(data, qty) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/squib/api/data.rb', line 106 def explode_quantities(data, qty) return data unless data.col? qty.to_s.strip qtys = data[qty] new_data = Squib::DataFrame.new data.each do |col, arr| new_data[col] = [] qtys.each_with_index do |qty, index| qty.to_i.times { new_data[col] << arr[index] } end end return new_data end |
.logger ⇒ Logger
Access the internal logger that Squib uses. By default, Squib configure the logger to the WARN level Use this to suppress or increase output levels.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/squib.rb', line 20 def logger if @logger.nil? @logger = Logger.new($stdout) @logger.level = Logger::WARN @logger.formatter = proc do |severity, datetime, m_progname, msg| "#{datetime} #{severity}: #{msg}\n" end end @logger end |
.xlsx(opts = {}) ⇒ Object
DSL method. See squib.readthedocs.io
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/squib/api/data.rb', line 12 def xlsx(opts = {}) input = Args::InputFile.new(file: 'deck.xlsx').load!(opts) import = Args::Import.new.load!(opts) s = Roo::Excelx.new(input.file[0]) s.default_sheet = s.sheets[input.sheet[0]] data = Squib::DataFrame.new s.first_column.upto(s.last_column) do |col| header = s.cell(s.first_row, col).to_s header.strip! if import.strip? data[header] = [] (s.first_row + 1).upto(s.last_row) do |row| cell = s.cell(row, col) # Roo hack for avoiding unnecessary .0's on whole integers (https://github.com/roo-rb/roo/issues/139) cell = s.excelx_value(row, col) if s.excelx_type(row, col) == [:numeric_or_formula, 'General'] cell.strip! if cell.respond_to?(:strip) && import.strip? cell = yield(header, cell) if block_given? data[header] << cell end# row end# col explode_quantities(data, import.explode) end |
.yaml(opts = {}) ⇒ Object
DSL method. See squib.readthedocs.io
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/squib/api/data.rb', line 72 def yaml(opts = {}) input = Args::InputFile.new(file: 'deck.yml').load!(opts) import = Args::Import.new.load!(opts) yml = YAML.load_file(input.file[0]) data = Squib::DataFrame.new # Get a universal list of keys to ensure everything is covered. keys = yml.map { |c| c.keys}.flatten.uniq keys.each { |k| data[k] = [] } #init arrays yml.each do |card| # nil value if key isn't set. keys.each { |k| data[k] << card[k] } end if block_given? data.each do |header, col| col.map! do |val| yield(header, val) end end end explode_quantities(data, import.explode) end |