Module: Qrcodeable::Core
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/qrcodeable/core.rb
Defined Under Namespace
Modules: ClassMethods
Classes: QrcodeableError
Instance Method Summary
collapse
Instance Method Details
#can_expire? ⇒ Boolean
83
84
85
|
# File 'lib/qrcodeable/core.rb', line 83
def can_expire?
self.expire_mode
end
|
#generate_qrcode ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/qrcodeable/core.rb', line 30
def generate_qrcode
begin
return ::RQRCode::QRCode.new(instance_value_of(self.identifier).to_s, level: :h)
rescue RuntimeError => e
raise QrcodeableError.invalid_identifier(self.identifier)
end
end
|
#print_qrcode ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/qrcodeable/core.rb', line 38
def print_qrcode
begin
qrcode = generate_qrcode
png = qrcode.as_png(
resize_gte_to: false,
resize_exactly_to: false,
fill: 'white',
color: 'black',
size: 512,
border_modules: 0,
module_px_size: 1,
file: nil
)
path = qrcode_path
File.open(path, 'wb') do |file|
file.write(png.to_s)
end
return path
rescue Errno::ENOENT => e
raise QrcodeableError.no_directory(self.print_path)
rescue RuntimeError => e
raise QrcodeableError.invalid_identifier(self.identifier)
end
end
|
#qrcode_expired? ⇒ Boolean
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/qrcodeable/core.rb', line 71
def qrcode_expired?
if can_expire?
if instance_value_of(self.expire_column)
(Time.now > instance_value_of(self.expire_column))
else
false
end
else
false
end
end
|
#qrcode_path ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/qrcodeable/core.rb', line 63
def qrcode_path
begin
::Rails.root.to_s+"/"+self.print_path+"/"+instance_value_of(self.identifier).to_s+".png"
rescue RuntimeError => e
raise QrcodeableError.invalid_identifier(self.identifier)
end
end
|