Class: CTioga2::MetaBuilder::Types::MarginsType

Inherits:
CTioga2::MetaBuilder::Type show all
Defined in:
lib/ctioga2/metabuilder/types/coordinates.rb

Overview

A class that produces a Graphics::Types::MarginsBox. It takes one optional argument : a :default (:frame, :figure or :page), see Graphics::Types::Dimensions::from_text for more information.

Instance Attribute Summary

Attributes inherited from CTioga2::MetaBuilder::Type

#namespace, #namespace_lookup, #passthrough, #re_shortcuts, #shortcuts, #type

Instance Method Summary collapse

Methods inherited from CTioga2::MetaBuilder::Type

#boolean?, #default_value, from_string, get_param_type, get_type, #initialize, #option_parser_long_option, #option_parser_option, #string_to_type, #type_name, type_name, #type_to_string

Constructor Details

This class inherits a constructor from CTioga2::MetaBuilder::Type

Instance Method Details

#string_to_type_internal(str) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ctioga2/metabuilder/types/coordinates.rb', line 47

def string_to_type_internal(str)
  default = @type[:default] || :frame
  specs = str.split(/\s*,\s*/)
  if specs.size == 1
    specs = specs * 4
  elsif specs.size == 2
    specs = [specs[0], specs[0], specs[1], specs[1]]
  end
  if specs.size != 4
    raise IncorrectInput, "You need either 1, 2 or 4 elements to make up a margin specification"
  end
  return Graphics::Types::MarginsBox.new(*specs.map {|x|
                                           Graphics::Types::Dimension::from_text(x, :x, default )})
end