Class: Antex::TexBox

Inherits:
Measurable show all
Defined in:
lib/antex/tex_box.rb

Overview

Loads and manages measures for TeX boxes.

Instance Attribute Summary

Attributes inherited from Measurable

#default_unit, #measures

Instance Method Summary collapse

Methods inherited from Measurable

#initialize

Constructor Details

This class inherits a constructor from Antex::Measurable

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Antex::Measurable

Instance Method Details

#load(filepath) ⇒ TexBox

Loads a YAML file containing TeX measures.

The expected input is a hash of named pt lenghts. E.g.:

pt: 1.0pt
wd: 5.0pt
ht: 8.0pt
dp: 2.0pt

Parameters:

  • filepath (String)

    the path of the YAML file to load

Returns:

  • (TexBox)

    returns self after loading



20
21
22
23
24
25
26
27
28
# File 'lib/antex/tex_box.rb', line 20

def load(filepath)
  yaml_hash = YAML.safe_load File.read(filepath)
  units = yaml_hash.keys.map(&:to_sym)
  magnitudes = yaml_hash.values.map { |value| value.chomp('pt').to_f }
  @measures = units.zip(magnitudes).to_h
  @measures[:pt] ||= 1.0
  @default_unit = :pt
  self
end