Module: Squib

Defined in:
lib/squib/deck.rb,
lib/squib.rb,
lib/squib/card.rb,
lib/squib/version.rb,
lib/squib/api/data.rb,
lib/squib/api/save.rb,
lib/squib/api/text.rb,
lib/squib/progress.rb,
lib/squib/api/image.rb,
lib/squib/api/units.rb,
lib/squib/constants.rb,
lib/squib/api/shapes.rb,
lib/squib/api/settings.rb,
lib/squib/commands/new.rb,
lib/squib/graphics/text.rb,
lib/squib/input_helpers.rb,
lib/squib/layout_parser.rb,
lib/squib/api/background.rb,
lib/squib/graphics/image.rb,
lib/squib/graphics/shapes.rb,
lib/squib/graphics/save_doc.rb,
lib/squib/graphics/showcase.rb,
lib/squib/graphics/background.rb,
lib/squib/graphics/save_images.rb

Overview

The project module

Defined Under Namespace

Modules: Commands Classes: Card, Deck

Constant Summary collapse

VERSION =

The next version to be released. Uses semantic versioning: http://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.2.0'
SYSTEM_DEFAULTS =

Squib's defaults for when arguments are not specified in the command nor layouts.

{
  :align => :left,
  :alpha => 1.0,
  :angle => 0,
  :blend => :none,
  :color => :black,
  :columns => 1,
  :default_font => 'Arial 36',
  :dir => '_output',
  :ellipsize => :end,
  :face => :left,
  :fill_color => '#0000',
  :force_id => false,
  :font => :use_set,
  :font_size => nil,
  :format => :png,
  :gap => 0,
  :height => :native,
  :hint => :off,
  :img_dir => '.',
  :justify => false,
  :margin => 75,
  :markup => false,
  :offset => 1.1,
  :prefix => 'card_',
  :progress_bar => false,
  :reflect_offset => 15,
  :reflect_percent => 0.25,
  :reflect_strength => 0.2,
  :range => :all,
  :rotate => false,
  :rows => :infinite,
  :scale => 0.85,
  :sheet => 0,
  :spacing => 0,
  :str => '',
  :stroke_color => :black,
  :stroke_width => 2.0,
  :trim => 0,
  :trim_radius => 38,
  :valign => :top,
  :width => :native,
  :wrap => true,
  :x => 0,
  :x1 => 100,
  :x2 => 150,
  :x3 => 100,
  :x_radius => 0,
  :y => 0,
  :y1 => 100,
  :y2 => 150,
  :y3 => 150,
  :y_radius => 0,
}
CONFIG_DEFAULTS =

Squib's configuration defaults

{
  'custom_colors' => {},
  'dpi' => 300,
  'hint' => :none,
  'progress_bar' => false,
  'img_dir' => '.',
}
UNIT_CONVERSION_PARAMS =

These parameters are considered for unit conversion

For example text str: 'Hello, World', x: '1in'

key: the internal name of the param (e.g. :circle_radius) value: the user-facing API key (e.g. radius: '1in')

{
  :circle_radius => :radius,
  :height => :height,
  :rect_radius => :radius,
  :spacing => :spacing,
  :stroke_width => :stroke_width,
  :width => :width,
  :x => :x,
  :x1 => :x1,
  :x2 => :x2,
  :x3 => :x3,
  :x_radius => :x_radius,
  :y => :y,
  :y1 => :y1,
  :y2 => :y2,
  :y3 => :y3,
  :y_radius => :y_radius,
}

Class Method Summary collapse

Class Method Details

.csv(opts = {}) ⇒ Hash

Pulls CSV data from .csv files into a column-based hash

Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row. See the example samples/csv.rb in the source repository

Parsing uses Ruby's CSV, with options {headers: true, converters: :numeric} http://www.ruby-doc.org/stdlib-2.0/libdoc/csv/rdoc/CSV.html

Examples:

# File data.csv looks like this (without the comment symbols)
# h1,h2
# 1,2
# 3,4
data = csv file: 'data.csv'
=> {'h1' => [1,3], 'h2' => [2,4]}

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • file (String)

    the CSV-formatted file to open. Opens relative to the current directory.

Returns:

  • (Hash)

    a hash of arrays based on columns in the table



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/squib/api/data.rb', line 63

def csv(opts = {})
  opts = Squib::SYSTEM_DEFAULTS.merge(opts)
  opts = Squib::InputHelpers.fileify(opts)
  table = CSV.read(opts[:file], headers: true, converters: :numeric)
  check_duplicate_csv_headers(table)
  hash = Hash.new
  table.headers.each do |header|
    hash[header.to_s] ||= table[header]
  end
  return hash
end

.loggerLogger

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.

Examples:

Squib.logger.level = Logger::DEBUG #show waaaay more information than you probably need, unless you're a dev
Squib.logger.level = Logger::ERROR #basically turns it off

Returns:

  • (Logger)

    the ruby logger



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 = {}) ⇒ Hash

Pulls Excel data from .xlsx files into a column-based hash

Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row. See the example samples/excel.rb in the source repository

Examples:

# Excel file looks like this:
# | h1 | h2 |
# ------------
# | 1  | 2  |
# | 3  | 4  |
data = xlsx file: 'data.xlsx', sheet: 0
{'h1' => [1,3], 'h2' => [2,4]}

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • file (String)

    the file to open. Must end in .xlsx. Opens relative to the current directory.

  • sheet (Integer) — default: 0

    The zero-based index of the sheet from which to read.

Returns:

  • (Hash)

    a hash of arrays based on columns in the spreadsheet



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/squib/api/data.rb', line 24

def xlsx(opts = {})
  opts = Squib::SYSTEM_DEFAULTS.merge(opts)
  opts = Squib::InputHelpers.fileify(opts)
  s = Roo::Excelx.new(opts[:file])
  s.default_sheet = s.sheets[opts[:sheet]]
  data = {}
  s.first_column.upto(s.last_column) do |col|
    header = s.cell(s.first_row,col).to_s
    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
      cell = s.excelx_value(row,col) if s.excelx_type(row,col) == [:numeric_or_formula, 'General']
      data[header] << cell
    end#row
  end#col
  data
end