Class: RQRCode::Renderer::Body

Inherits:
Object
  • Object
show all
Defined in:
lib/rqrcode/renderer.rb

Direct Known Subclasses

ImageBody, SvgBody

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(modules, type, options = {}) ⇒ Body

Returns a new instance of Body.



46
47
48
49
50
# File 'lib/rqrcode/renderer.rb', line 46

def initialize modules, type, options={}
  self.modules = modules
  self.type = type
  self.options = options
end

Instance Attribute Details

#modulesObject

Returns the value of attribute modules.



35
36
37
# File 'lib/rqrcode/renderer.rb', line 35

def modules
  @modules
end

#optionsObject

Returns the value of attribute options.



35
36
37
# File 'lib/rqrcode/renderer.rb', line 35

def options
  @options
end

#typeObject

Returns the value of attribute type.



35
36
37
# File 'lib/rqrcode/renderer.rb', line 35

def type
  @type
end

Class Method Details

.new(modules, type, options = {}) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/rqrcode/renderer.rb', line 37

def self.new modules, type, options={}
  return super unless self == Body
  if type == "image/svg+xml"
    SvgBody
  else
    ImageBody
  end.new modules, type, options
end

Instance Method Details

#heightObject



56
57
58
# File 'lib/rqrcode/renderer.rb', line 56

def height
  modules.length
end

#scaleObject



60
61
62
# File 'lib/rqrcode/renderer.rb', line 60

def scale
  @scale ||= [options[:scale].to_i, 1].max
end

#widthObject



52
53
54
# File 'lib/rqrcode/renderer.rb', line 52

def width
  modules.first.length
end