Class: Device::Application

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, file_path, type, crc) ⇒ Application

Returns a new instance of Application.



5
6
7
8
9
10
11
# File 'lib/device/application.rb', line 5

def initialize(label, file_path, type, crc)
  @name = label
  @order, @label = split_label(label)
  @file_path = file_path
  @type      = type
  @crc       = crc
end

Instance Attribute Details

#crcObject (readonly)

Returns the value of attribute crc.



3
4
5
# File 'lib/device/application.rb', line 3

def crc
  @crc
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



3
4
5
# File 'lib/device/application.rb', line 3

def file_path
  @file_path
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/device/application.rb', line 3

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/device/application.rb', line 3

def name
  @name
end

#orderObject (readonly)

Returns the value of attribute order.



3
4
5
# File 'lib/device/application.rb', line 3

def order
  @order
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/device/application.rb', line 3

def type
  @type
end

Instance Method Details

#execute(json = "") ⇒ Object



33
34
35
# File 'lib/device/application.rb', line 33

def execute(json = "")
  Device::Runtime.execute(file_no_ext, json)
end

#fileObject



13
14
15
# File 'lib/device/application.rb', line 13

def file
  @file ||= file_path.gsub("#{Device::Setting.company_name}_", "")
end

#file_no_extObject



17
18
19
# File 'lib/device/application.rb', line 17

def file_no_ext
  @file_no_ext ||= file.split(".")[0]
end

#outdated?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/device/application.rb', line 25

def outdated?
  return false unless File.exists?(@file_path)
  file = File.open(@file_path)
  Device::Crypto.crc16_hex(file.read) == @crc
ensure
  file.close if file
end

#zipObject



21
22
23
# File 'lib/device/application.rb', line 21

def zip
  @zip ||= "#{file_no_ext}.zip"
end