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/args/unit_conversion.rb,
lib/squib/graphics/save_images.rb,
lib/squib/graphics/gradient_regex.rb,
lib/squib/graphics/cairo_context_wrapper.rb
Overview
The project module
Defined Under Namespace
Modules: Args, Commands, Graphics 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.3.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, :count_format => '%02d', :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, :mask => nil, :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, :gap => :gap, :height => :height, :margin => :margin, :paper_width => :width, :paper_height => :height, :rect_radius => :radius, :spacing => :spacing, :stroke_width => :stroke_width, :trim => :trim, :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
-
.csv(opts = {}) ⇒ Hash
Pulls CSV data from
.csv
files into a column-based hash. -
.logger ⇒ Logger
Access the internal logger that Squib uses.
-
.xlsx(opts = {}) ⇒ Hash
Pulls Excel data from
.xlsx
files into a column-based hash.
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
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 |
.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 = {}) ⇒ 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
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 |