Class: Laser::Cutter::PageManager
- Inherits:
-
Struct
- Object
- Struct
- Laser::Cutter::PageManager
- Defined in:
- lib/laser-cutter/page_manager.rb
Constant Summary collapse
- SIZES =
PDF::Core::PageGeometry::SIZES.clone.freeze
Instance Attribute Summary collapse
-
#units ⇒ Object
Returns the value of attribute units.
Instance Method Summary collapse
- #all_page_sizes ⇒ Object
- #page_size_values ⇒ Object
-
#value_from_units(value, from_units = nil) ⇒ Object
if from_units is nil, we expect it to be in dots per inch (default measurements for Prawn.
Instance Attribute Details
#units ⇒ Object
Returns the value of attribute units
5 6 7 |
# File 'lib/laser-cutter/page_manager.rb', line 5 def units @units end |
Instance Method Details
#all_page_sizes ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/laser-cutter/page_manager.rb', line 8 def all_page_sizes output = "" page_size_values.each do |k| output << sprintf("\t%10s:\t%6.1f x %6.1f\n", *k) end output end |
#page_size_values ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/laser-cutter/page_manager.rb', line 35 def page_size_values h = SIZES array = [] h.keys.sort.each do |k| array << [k, value_from_units(h[k][0].to_f), value_from_units(h[k][1].to_f)] end array end |
#value_from_units(value, from_units = nil) ⇒ Object
if from_units is nil, we expect it to be in dots per inch (default measurements for Prawn
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/laser-cutter/page_manager.rb', line 18 def value_from_units value, from_units = nil multiplier = if from_units.nil? if units.eql?('in') 1.0 / 72.0 # PDF units per inch else 25.4 * 1.0 / 72.0 end elsif self.units.eql?(from_units) 1.0 elsif self.units.eql?('in') && from_units.eql?('mm') (1.0 / 25.4) else 25.4 end value.to_f * multiplier end |