Class: Prawn::SwissQRBill::Specifications
- Inherits:
-
Object
- Object
- Prawn::SwissQRBill::Specifications
- Defined in:
- lib/prawn/swiss_qr_bill/specifications.rb
Overview
Access common style specifications according to the style guide.
Reference: www.paymentstandards.ch/dam/downloads/style-guide-en.pdf
Defined Under Namespace
Classes: Spec
Constant Summary collapse
- SPECS_FILE =
'specs.yml'
- DEFAULTS =
{ point: Spec.new(nil, ->(v) { from_mm(v) }), width: Spec.new(nil, ->(v) { from_mm(v) }), height: Spec.new(nil, ->(v) { from_mm(v) }), content_font_size: Spec.new, content_font_leading: Spec.new(0), content_font_style: Spec.new(:normal, ->(v) { v.to_sym }), label_font_size: Spec.new, label_font_leading: Spec.new(0), label_font_style: Spec.new(:bold, ->(v) { v.to_sym }) }.freeze
Class Method Summary collapse
-
.from_mm(value) ⇒ Object
Transform a value or an array of values from mm to pt.
Instance Method Summary collapse
- #get(spec_key) ⇒ Object
- #get_specs(spec_key) ⇒ Object
-
#initialize ⇒ Specifications
constructor
A new instance of Specifications.
Constructor Details
#initialize ⇒ Specifications
Returns a new instance of Specifications.
28 29 30 31 |
# File 'lib/prawn/swiss_qr_bill/specifications.rb', line 28 def initialize # OPTIMIZE: unnessecary assignement @specs = load_specs end |
Class Method Details
.from_mm(value) ⇒ Object
Transform a value or an array of values from mm to pt
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/prawn/swiss_qr_bill/specifications.rb', line 57 def self.from_mm(value) case value when Numeric value.mm when Array value.map(&:mm) else value end end |
Instance Method Details
#get(spec_key) ⇒ Object
33 34 35 |
# File 'lib/prawn/swiss_qr_bill/specifications.rb', line 33 def get(spec_key) @specs.dig(*key_path(spec_key)) || {} end |
#get_specs(spec_key) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/prawn/swiss_qr_bill/specifications.rb', line 37 def get_specs(spec_key) # get hash from yaml by path spec_values = get(spec_key) values = {} DEFAULTS.each_key do |key| # set defaults values[key] = DEFAULTS[key].default # overwrite if set values[key] = spec_values[key.to_s] if spec_values.key?(key.to_s) # format values[key] = DEFAULTS[key][:format].call(values[key]) if DEFAULTS[key][:format].is_a?(Proc) end spec_values = values.values_at(*DEFAULTS.keys) Struct.new(*DEFAULTS.keys).new(*spec_values) end |