Browse Source

Refactoring and documentation

dev
Andy Meneely 11 years ago
parent
commit
0da51b4573
  1. 2
      lib/squib/api/data.rb
  2. 5
      lib/squib/api/units.rb
  3. 3
      lib/squib/card.rb
  4. 5
      lib/squib/constants.rb
  5. 3
      lib/squib/deck.rb
  6. 4
      lib/squib/graphics/save_doc.rb
  7. 5
      lib/squib/input_helpers.rb

2
lib/squib/api/data.rb

@ -54,7 +54,7 @@ module Squib
# data = csv file: 'data.csv' # data = csv file: 'data.csv'
# => {'h1' => [1,3], 'h2' => [2,4]} # => {'h1' => [1,3], 'h2' => [2,4]}
# #
# Parsing uses Ruby's CSV, options: {headers: true, converters: :numeric} # Parsing uses Ruby's CSV, with options `{headers: true, converters: :numeric}`
# http://www.ruby-doc.org/stdlib-2.0/libdoc/csv/rdoc/CSV.html # http://www.ruby-doc.org/stdlib-2.0/libdoc/csv/rdoc/CSV.html
# #
# @option opts file [String] the CSV-formatted file to open. Opens relative to the current directory. # @option opts file [String] the CSV-formatted file to open. Opens relative to the current directory.

5
lib/squib/api/units.rb

@ -1,3 +1,5 @@
require 'squib/constants'
module Squib module Squib
class Deck class Deck
@ -13,7 +15,6 @@ module Squib
@dpi * n.to_f @dpi * n.to_f
end end
@@INCHES_IN_CM = 0.393700787
# Given cm, returns the number of pixels according to the deck's DPI. # Given cm, returns the number of pixels according to the deck's DPI.
# #
# @example # @example
@ -23,7 +24,7 @@ module Squib
# @return [Decimal] the number of pixels, according to the deck's DPI # @return [Decimal] the number of pixels, according to the deck's DPI
# @api public # @api public
def cm(n) def cm(n)
@dpi * @@INCHES_IN_CM * n.to_f @dpi * Squib::INCHES_IN_CM * n.to_f
end end
end end

3
lib/squib/card.rb

@ -22,6 +22,9 @@ module Squib
@cairo_context = Cairo::Context.new(@cairo_surface) @cairo_context = Cairo::Context.new(@cairo_surface)
end end
# A save/restore wrapper for using Cairo
# :nodoc:
# @api private
def use_cairo(&block) def use_cairo(&block)
@cairo_context.save @cairo_context.save
block.yield(@cairo_context) block.yield(@cairo_context)

5
lib/squib/constants.rb

@ -134,4 +134,9 @@ module Squib
:y3 => :y3, :y3 => :y3,
:y_radius => :y_radius, :y_radius => :y_radius,
} }
# Used for inch-cm conversion
# :nodoc:
# @api private
INCHES_IN_CM = 0.393700787
end end

3
lib/squib/deck.rb

@ -169,6 +169,9 @@ module Squib
end end
end end
# Use Logger to show more detail on the run
# :nodoc:
# @api private
def show_info(config, layout) def show_info(config, layout)
Squib::logger.info "Squib v#{Squib::VERSION}" Squib::logger.info "Squib v#{Squib::VERSION}"
Squib::logger.info " building #{@cards.size} #{@width}x#{@height} cards" Squib::logger.info " building #{@cards.size} #{@width}x#{@height} cards"

4
lib/squib/graphics/save_doc.rb

@ -95,8 +95,8 @@ module Squib
# #
# @param surface The surface to trim # @param surface The surface to trim
# @param trim The number of pixels around the edge to trim # @param trim The number of pixels around the edge to trim
# @width width The width of the surface prior to the trim # @param width The width of the surface prior to the trim
# @height height The height of the surface prior to the trim # @param height The height of the surface prior to the trim
# :nodoc: # :nodoc:
# @api private # @api private
def trim(surface, trim, width, height) def trim(surface, trim, width, height)

5
lib/squib/input_helpers.rb

@ -192,7 +192,6 @@ module Squib
end end
module_function :rotateify module_function :rotateify
@@INCHES_IN_CM = 0.393700787
# Convert units # Convert units
# :nodoc: # :nodoc:
# @api private # @api private
@ -204,7 +203,7 @@ module Squib
when /in$/ #ends with "in" when /in$/ #ends with "in"
opts[api_param][i] = arg.rstrip[0..-2].to_f * @dpi opts[api_param][i] = arg.rstrip[0..-2].to_f * @dpi
when /cm$/ #ends with "cm" when /cm$/ #ends with "cm"
opts[api_param][i] = arg.rstrip[0..-2].to_f * @dpi * @@INCHES_IN_CM opts[api_param][i] = arg.rstrip[0..-2].to_f * @dpi * Squib::INCHES_IN_CM
end end
end end
end end
@ -226,7 +225,5 @@ module Squib
opts opts
end end
end end
end end

Loading…
Cancel
Save