Class: Prawn::Labels
- Inherits:
-
Object
- Object
- Prawn::Labels
- Defined in:
- lib/prawn/labels.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .generate(file_name, data, options = {}, &block) ⇒ Object
- .render(data, options = {}, &block) ⇒ Object
- .types ⇒ Object
- .types=(custom_types) ⇒ Object
Instance Method Summary collapse
-
#initialize(data, options = {}, &block) ⇒ Labels
constructor
A new instance of Labels.
Constructor Details
#initialize(data, options = {}, &block) ⇒ Labels
Returns a new instance of Labels.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/prawn/labels.rb', line 43 def initialize(data, = {}, &block) unless @type = Labels.types[[:type]] raise "Label Type Unknown '#{[:type]}'" end type["paper_size"] ||= "A4" type["top_margin"] ||= 36 type["left_margin"] ||= 36 [:document] ||= {} .merge!(:vertical_text => true) if type["vertical_text"] @document = Document.new [:document].merge( :page_size => type["paper_size"], :top_margin => type["top_margin"], :bottom_margin => type["bottom_margin"], :left_margin => type["left_margin"], :right_margin => type["right_margin"]) generate_grid @type data.each_with_index do |record, index| if (defined? record.vertical_text) .merge!(:vertical_text => record.vertical_text) end create_label(index, record, ) do |pdf, record| yield pdf, record end end end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
12 13 14 |
# File 'lib/prawn/labels.rb', line 12 def document @document end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/prawn/labels.rb', line 12 def type @type end |
Class Method Details
.generate(file_name, data, options = {}, &block) ⇒ Object
16 17 18 19 |
# File 'lib/prawn/labels.rb', line 16 def generate(file_name, data, = {}, &block) labels = Labels.new(data, , &block) labels.document.render_file(file_name) end |
.render(data, options = {}, &block) ⇒ Object
21 22 23 24 |
# File 'lib/prawn/labels.rb', line 21 def render(data, = {}, &block) labels = Labels.new(data, , &block) labels.document.render end |
.types ⇒ Object
34 35 36 37 38 39 |
# File 'lib/prawn/labels.rb', line 34 def types @types ||= begin types_file = File.join(File.dirname(__FILE__), 'types.yaml') YAML.load_file(types_file) end end |
.types=(custom_types) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/prawn/labels.rb', line 26 def types=(custom_types) if custom_types.is_a? Hash types.merge! custom_types elsif custom_types.is_a?(String) && File.exist?(custom_types) types.merge! YAML.load_file(custom_types) end end |