module BerkeleyLibrary::TIND::Export::Config

Constants

FONT_SIZE_DEFAULT

Font size in points

FORMAT_DIGITS_DEFAULT

Decimal places for formatting

HEIGHT_INCREMENT_DEFAULT_POINTS

Round row heights up to nearest 2 points

LINE_HEIGHT_DEFAULT_EM

Line height as multiple of font size

MAX_COLUMN_WIDTH_INCHES

Max column width before wrapping

WIDTH_INCREMENT_DEFAULT_INCHES

Round column widths up to nearest eighth inch

Public Class Methods

font_size_pt() click to toggle source

@return [Numeric] the font size in points

# File lib/berkeley_library/tind/export/config.rb, line 58
def font_size_pt
  @font_size_pt ||= ensure_positive_numeric(ENV['ODS_FONT_SIZE_DEFAULT'] || Config::FONT_SIZE_DEFAULT)
end
font_size_pt=(value) click to toggle source
# File lib/berkeley_library/tind/export/config.rb, line 62
def font_size_pt=(value)
  @font_size_pt = ensure_positive_numeric(value)
end
format_digits() click to toggle source

@return [Integer] the number of digits to use when formatting values

# File lib/berkeley_library/tind/export/config.rb, line 103
def format_digits
  @format_digits ||= ensure_positive_int(ENV['ODS_FORMAT_DIGITS_DEFAULT'] || Config::FORMAT_DIGITS_DEFAULT)
end
format_digits=(value) click to toggle source
# File lib/berkeley_library/tind/export/config.rb, line 107
def format_digits=(value)
  @format_digits = ensure_positive_int(value)
end
h_incr_pt() click to toggle source

@return [Numeric] the height rounding increment in points

# File lib/berkeley_library/tind/export/config.rb, line 85
def h_incr_pt
  @h_incr_pt ||= ensure_positive_numeric(ENV['ODS_HEIGHT_INCREMENT_DEFAULT_POINTS'] || Config::HEIGHT_INCREMENT_DEFAULT_POINTS)
end
h_incr_pt=(value) click to toggle source
# File lib/berkeley_library/tind/export/config.rb, line 89
def h_incr_pt=(value)
  @h_incr_pt = ensure_positive_numeric(value)
end
line_height_em() click to toggle source

@return [Numeric] the line height in ems (multiples of the font point size)

# File lib/berkeley_library/tind/export/config.rb, line 94
def line_height_em
  @line_height_em ||= ensure_positive_numeric(ENV['ODS_LINE_HEIGHT_DEFAULT_EM'] || Config::LINE_HEIGHT_DEFAULT_EM)
end
line_height_em=(value) click to toggle source
# File lib/berkeley_library/tind/export/config.rb, line 98
def line_height_em=(value)
  @line_height_em = ensure_positive_numeric(value)
end
max_col_width_in() click to toggle source

@return [Numeric] the max column width in inches

# File lib/berkeley_library/tind/export/config.rb, line 67
def max_col_width_in
  @max_col_width_in ||= ensure_positive_numeric(ENV['ODS_MAX_COLUMN_WIDTH_INCHES'] || Config::MAX_COLUMN_WIDTH_INCHES)
end
max_col_width_in=(value) click to toggle source
# File lib/berkeley_library/tind/export/config.rb, line 71
def max_col_width_in=(value)
  @max_col_width_in = ensure_positive_numeric(value)
end
w_incr_in() click to toggle source

@return [Numeric] the width rounding increment in inches

# File lib/berkeley_library/tind/export/config.rb, line 76
def w_incr_in
  @w_incr_in ||= ensure_positive_numeric(ENV['ODS_WIDTH_INCREMENT_DEFAULT_INCHES'] || Config::WIDTH_INCREMENT_DEFAULT_INCHES)
end
w_incr_in=(value) click to toggle source
# File lib/berkeley_library/tind/export/config.rb, line 80
def w_incr_in=(value)
  @w_incr_in = ensure_positive_numeric(value)
end

Private Class Methods

ensure_int(v) click to toggle source
# File lib/berkeley_library/tind/export/config.rb, line 142
def ensure_int(v)
  return v if v.is_a?(Integer)

  v_str = v.to_s
  return Integer(v_str) if v_str =~ /(?:0x\h+|\d+)/

  raise ArgumentError, "Can't parse #{v.inspect} as an integer value"
end
ensure_numeric(v) click to toggle source
# File lib/berkeley_library/tind/export/config.rb, line 122
def ensure_numeric(v)
  return v if v.is_a?(Numeric)

  v_str = v.to_s
  return v_str.to_r if v_str.include?('/')
  return v_str.to_f if v_str.include?('.')
  return Integer(v_str) if v_str =~ /(?:0x\h+|\d+)/

  raise ArgumentError, "Can't parse #{v.inspect} as a numeric value"
end
ensure_positive_int(v) click to toggle source

@param v [Object] a value @return [Integer]

# File lib/berkeley_library/tind/export/config.rb, line 135
def ensure_positive_int(v)
  v_i = ensure_int(v)
  return v_i if v_i > 0

  raise ArgumentError, "Value must be positive: #{v_i}"
end
ensure_positive_numeric(v) click to toggle source

@param v [Object] a value @return [Numeric] a numeric value, or nil if the value is not numeric

# File lib/berkeley_library/tind/export/config.rb, line 115
def ensure_positive_numeric(v)
  v_n = ensure_numeric(v)
  return v_n if v_n > 0

  raise ArgumentError, "Value must be positive: #{v_n}"
end

Public Instance Methods

font_size_pt() click to toggle source

@return [Numeric] the font size in points

# File lib/berkeley_library/tind/export/config.rb, line 25
def font_size_pt
  Config.font_size_pt
end
format_digits() click to toggle source

@return [Integer] the number of digits to use when formatting values

# File lib/berkeley_library/tind/export/config.rb, line 50
def format_digits
  Config.format_digits
end
h_incr_pt() click to toggle source

@return [Numeric] the height rounding increment in points

# File lib/berkeley_library/tind/export/config.rb, line 40
def h_incr_pt
  Config.h_incr_pt
end
line_height_em() click to toggle source

@return [Numeric] the line height in ems (multiples of the font point size)

# File lib/berkeley_library/tind/export/config.rb, line 45
def line_height_em
  Config.line_height_em
end
max_col_width_in() click to toggle source

@return [Numeric] the max column width in inches

# File lib/berkeley_library/tind/export/config.rb, line 30
def max_col_width_in
  Config.max_col_width_in
end
w_incr_in() click to toggle source

@return [Numeric] the width rounding increment in inches

# File lib/berkeley_library/tind/export/config.rb, line 35
def w_incr_in
  Config.w_incr_in
end