Class: NetLinx::SystemFile

Inherits:
Object
  • Object
show all
Defined in:
lib/netlinx/workspace/system_file.rb

Overview

A file node in a NetLinx::System.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ SystemFile

Returns a new instance of SystemFile.

Parameters:

  • kwargs (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • :system (NetLinx::System)

    This file’s parent system node.

  • :name (String) — default: ''

    Identifiable name.

  • :path (String) — default: ''

    Relative file path.

  • :description (String) — default: ''
  • :type (:master, :source, :include, :duet, :tko, :module, :ir, :tp4, :tp5) — default: :master


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/netlinx/workspace/system_file.rb', line 19

def initialize **kwargs
  @system      = kwargs.fetch :system,      nil
  
  @name        = kwargs.fetch :name,        ''
  @path        = kwargs.fetch :path,        ''
  @description = kwargs.fetch :description, ''
  @type        = kwargs.fetch :type,        :master
  
  @devices = []
  
  system_file_element = kwargs.fetch :element, nil
  parse_xml_element system_file_element if system_file_element
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



9
10
11
# File 'lib/netlinx/workspace/system_file.rb', line 9

def description
  @description
end

#devicesObject

Array of D:P:S strings that this file maps to.



12
13
14
# File 'lib/netlinx/workspace/system_file.rb', line 12

def devices
  @devices
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/netlinx/workspace/system_file.rb', line 7

def name
  @name
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/netlinx/workspace/system_file.rb', line 8

def path
  @path
end

#systemObject

Returns the value of attribute system.



6
7
8
# File 'lib/netlinx/workspace/system_file.rb', line 6

def system
  @system
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/netlinx/workspace/system_file.rb', line 10

def type
  @type
end

Instance Method Details

#<<(device) ⇒ Object

Add a device that uses this file.

Parameters:

  • device (String)

    D:P:S string.



35
36
37
# File 'lib/netlinx/workspace/system_file.rb', line 35

def << device
  devices << device
end

#to_sObject

Returns the SystemFile’s name.

Returns:

  • the SystemFile’s name.



40
41
42
# File 'lib/netlinx/workspace/system_file.rb', line 40

def to_s
  @name
end

#to_xml_elementREXML::Element

Returns an XML element representing this file.

Returns:

  • (REXML::Element)

    an XML element representing this file.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/netlinx/workspace/system_file.rb', line 45

def to_xml_element
  REXML::Element.new('File').tap do |file|
    file.attributes['CompileType'] = 'Netlinx'
    
    file.attributes['Type'] = type_lookup[type]
    
    file.add_element('Identifier').tap { |e| e.text = name }
    file.add_element('FilePathName').tap { |e| e.text = path }
    file.add_element('Comments').tap { |e| e.text = description }
    
    @devices.each do |dps|
      file.add_element('DeviceMap').tap do |e|
        text = dps.include?(':') ? "Custom [#{dps}]" : dps
        e.attributes['DevAddr'] = text
        e.add_element('DevName').text = text
      end
    end
  end
end