From 0da51b45734754b9b2d9f474054f31080751713a Mon Sep 17 00:00:00 2001 From: Andy Meneely Date: Wed, 31 Dec 2014 09:17:21 -0500 Subject: [PATCH] Refactoring and documentation --- lib/squib/api/data.rb | 2 +- lib/squib/api/units.rb | 5 +++-- lib/squib/card.rb | 3 +++ lib/squib/constants.rb | 5 +++++ lib/squib/deck.rb | 3 +++ lib/squib/graphics/save_doc.rb | 4 ++-- lib/squib/input_helpers.rb | 5 +---- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/squib/api/data.rb b/lib/squib/api/data.rb index 29e3dc7..e0f1e5c 100644 --- a/lib/squib/api/data.rb +++ b/lib/squib/api/data.rb @@ -54,7 +54,7 @@ module Squib # data = csv file: 'data.csv' # => {'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 # # @option opts file [String] the CSV-formatted file to open. Opens relative to the current directory. diff --git a/lib/squib/api/units.rb b/lib/squib/api/units.rb index 498a3ed..7e17ae8 100644 --- a/lib/squib/api/units.rb +++ b/lib/squib/api/units.rb @@ -1,3 +1,5 @@ +require 'squib/constants' + module Squib class Deck @@ -13,7 +15,6 @@ module Squib @dpi * n.to_f end - @@INCHES_IN_CM = 0.393700787 # Given cm, returns the number of pixels according to the deck's DPI. # # @example @@ -23,7 +24,7 @@ module Squib # @return [Decimal] the number of pixels, according to the deck's DPI # @api public def cm(n) - @dpi * @@INCHES_IN_CM * n.to_f + @dpi * Squib::INCHES_IN_CM * n.to_f end end diff --git a/lib/squib/card.rb b/lib/squib/card.rb index 057f4b7..5ed1ccc 100644 --- a/lib/squib/card.rb +++ b/lib/squib/card.rb @@ -22,6 +22,9 @@ module Squib @cairo_context = Cairo::Context.new(@cairo_surface) end + # A save/restore wrapper for using Cairo + # :nodoc: + # @api private def use_cairo(&block) @cairo_context.save block.yield(@cairo_context) diff --git a/lib/squib/constants.rb b/lib/squib/constants.rb index a429753..d6e29ac 100644 --- a/lib/squib/constants.rb +++ b/lib/squib/constants.rb @@ -134,4 +134,9 @@ module Squib :y3 => :y3, :y_radius => :y_radius, } + + # Used for inch-cm conversion + # :nodoc: + # @api private + INCHES_IN_CM = 0.393700787 end diff --git a/lib/squib/deck.rb b/lib/squib/deck.rb index ecc4d75..14de164 100644 --- a/lib/squib/deck.rb +++ b/lib/squib/deck.rb @@ -169,6 +169,9 @@ module Squib end end + # Use Logger to show more detail on the run + # :nodoc: + # @api private def show_info(config, layout) Squib::logger.info "Squib v#{Squib::VERSION}" Squib::logger.info " building #{@cards.size} #{@width}x#{@height} cards" diff --git a/lib/squib/graphics/save_doc.rb b/lib/squib/graphics/save_doc.rb index a6cb6ec..d3d4b39 100644 --- a/lib/squib/graphics/save_doc.rb +++ b/lib/squib/graphics/save_doc.rb @@ -95,8 +95,8 @@ module Squib # # @param surface The surface to trim # @param trim The number of pixels around the edge to trim - # @width width The width of the surface prior to the trim - # @height height The height of the surface prior to the trim + # @param width The width of the surface prior to the trim + # @param height The height of the surface prior to the trim # :nodoc: # @api private def trim(surface, trim, width, height) diff --git a/lib/squib/input_helpers.rb b/lib/squib/input_helpers.rb index 79798a5..45257e5 100644 --- a/lib/squib/input_helpers.rb +++ b/lib/squib/input_helpers.rb @@ -192,7 +192,6 @@ module Squib end module_function :rotateify - @@INCHES_IN_CM = 0.393700787 # Convert units # :nodoc: # @api private @@ -204,7 +203,7 @@ module Squib when /in$/ #ends with "in" opts[api_param][i] = arg.rstrip[0..-2].to_f * @dpi 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 @@ -226,7 +225,5 @@ module Squib opts end - - end end