Module: ClockworkComicPDF::MeasurementParser
- Included in:
- PDFMaker
- Defined in:
- lib/clockwork_comic_pdf/measurement_parser.rb
Overview
stores the option parsing logic for PDFMaker
Instance Method Summary collapse
- #convert_complex_position(pdf, val) ⇒ Object
- #convert_position(pdf, val) ⇒ Object
- #convert_simple_position(pdf, val) ⇒ Object
- #convert_size(pdf, val, opt_in) ⇒ Object
- #convert_val(pdf, val, opt_in) ⇒ Object
- #get_h_center(pdf, opt_in) ⇒ Object
- #get_v_center(pdf, options) ⇒ Object
- #parse_options(pdf, opt_in) ⇒ Object
Instance Method Details
#convert_complex_position(pdf, val) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/clockwork_comic_pdf/measurement_parser.rb', line 35 def convert_complex_position(pdf, val) case val when :bounds_top_left then return pdf.bounds.top_left when :bounds_top_right then return pdf.bounds.top_right when :bounds_bottom_left then return pdf.bounds.bottom_left when :bounds_bottom_right then return pdf.bounds.bottom_right else return val end end |
#convert_position(pdf, val) ⇒ Object
29 30 31 32 33 |
# File 'lib/clockwork_comic_pdf/measurement_parser.rb', line 29 def convert_position(pdf, val) val = convert_complex_position(pdf, val) val = convert_simple_position(pdf, val) val end |
#convert_simple_position(pdf, val) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/clockwork_comic_pdf/measurement_parser.rb', line 45 def convert_simple_position(pdf, val) case val when :bounds_top then return pdf.bounds.top when :bounds_bottom then return pdf.bounds.bottom when :bounds_left then return pdf.bounds.left when :bounds_right then return pdf.bounds.right else return val end end |
#convert_size(pdf, val, opt_in) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/clockwork_comic_pdf/measurement_parser.rb', line 55 def convert_size(pdf, val, opt_in) case val when :bounds_width then return pdf.bounds.width when :bounds_height then return pdf.bounds.height when :bounds_center_width then return get_h_center(pdf, opt_in) when :bounds_center_height then return get_v_center(pdf, opt_in) else return val end end |
#convert_val(pdf, val, opt_in) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/clockwork_comic_pdf/measurement_parser.rb', line 16 def convert_val(pdf, val, opt_in) if val.is_a? Array val = Array.new(val) val.each_index do |i| val[i] = convert_val(pdf, val[i], opt_in) end else val = convert_position(pdf, val) val = convert_size(pdf, val, opt_in) end val end |
#get_h_center(pdf, opt_in) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/clockwork_comic_pdf/measurement_parser.rb', line 65 def get_h_center(pdf, opt_in) if !opt_in[:width_ratio].nil? box_width = opt_in[:width_ratio].to_r * pdf.bounds.width else box_width = opt_in[:width] end pdf.bounds.width / 2 - box_width / 2 end |
#get_v_center(pdf, options) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/clockwork_comic_pdf/measurement_parser.rb', line 74 def get_v_center(pdf, ) if !opt_in[:height_ratio].nil? box_height = opt_in[:height_ratio].to_r * pdf.bounds.height else box_height = opt_in[:height] end pdf.bounds.height / 2 - box_height / 2 end |
#parse_options(pdf, opt_in) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/clockwork_comic_pdf/measurement_parser.rb', line 4 def (pdf, opt_in) out = {} opt_in.each_pair do |key, val| case key when :height_ratio then out[:height] = pdf.bounds.height * val.to_r when :width_ratio then out[:width] = pdf.bounds.width * val.to_r else out[key] = convert_val(pdf, val, opt_in) end end out end |