Class: QR::Qr

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

Instance Method Summary collapse

Instance Method Details

#copy(src_path, dest_path) ⇒ Object



24
25
26
# File 'lib/Qr.rb', line 24

def copy src_path, dest_path
  FileUtils.cp(src_path, dest_path)
end

#dest_folder_path(path) ⇒ Object



32
33
34
# File 'lib/Qr.rb', line 32

def dest_folder_path path
  dest_folder = path.split('/').reverse.drop(1).reverse.join('/')
end

#extension(name) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/Qr.rb', line 40

def extension name
  extension = <<-EOS
extension #{name} {
\tfunc scan() {
\t\tself.openVedaQRScanner(source: self) { (viewcontroller, string) in
\t\tlet qrString = string
\t\tprint(qrString)
\t\t}
\t}

\tfunc openVedaQRScanner(source: UIViewController, completion: @escaping (VedaQRScannerViewController, String)->()) {
\t\tif let vc = UIStoryboard(name: "VedaQR", bundle: nil).instantiateInitialViewController() as? VedaQRScannerViewController {
\t\t\tvc.onObtained = completion
\t\t\tsource.present(vc, animated: true, completion: nil)
\t\t}
\t}
}
EOS
end

#generate_qr(path) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/Qr.rb', line 4

def generate_qr path
  qr_storyboard_path = root + '/lib/VedaQRScanner/VedaQr.storyboard'
  qr_viewcontroller_path = root + '/lib/VedaQRScanner/VedaQRScannerViewController.swift'
  viewcontroller_extension_path = root + '/lib/VedaQRScanner/UIViewControllerExtension.swift'

  dest_folder = dest_folder_path path
  copy qr_storyboard_path, dest_folder
  copy qr_viewcontroller_path, dest_folder
  copy viewcontroller_extension_path, dest_folder
  viewcontroller_name = viewcontroller_name path
  write((extension viewcontroller_name), path)
  puts "successfully generated qr scanner in path: #{dest_folder}"
end

#rootObject



28
29
30
# File 'lib/Qr.rb', line 28

def root
    File.expand_path '../..', __FILE__
end

#viewcontroller_name(path) ⇒ Object



36
37
38
# File 'lib/Qr.rb', line 36

def viewcontroller_name path
  path.split('/').reverse.first.split('.').first
end

#write(extension, path) ⇒ Object



18
19
20
21
22
# File 'lib/Qr.rb', line 18

def write extension, path
  f = File.open(path, 'a')
  f.write(extension)
  f.close
end