Class: Snap7::DataBlockRegistry
- Inherits:
-
Object
- Object
- Snap7::DataBlockRegistry
- Defined in:
- lib/ffi-snap7/data_structures/data_block_registry.rb
Instance Attribute Summary collapse
-
#dbs ⇒ Object
readonly
Returns the value of attribute dbs.
Instance Method Summary collapse
- #add_variable(ident, address, data_type) ⇒ Object
- #db(db_addr) ⇒ Object
- #each(&block) ⇒ Object
- #find_variable(ident) ⇒ Object
-
#initialize ⇒ DataBlockRegistry
constructor
A new instance of DataBlockRegistry.
- #sorted_dbs ⇒ Object
Constructor Details
#initialize ⇒ DataBlockRegistry
Returns a new instance of DataBlockRegistry.
6 7 8 |
# File 'lib/ffi-snap7/data_structures/data_block_registry.rb', line 6 def initialize @dbs = {} end |
Instance Attribute Details
#dbs ⇒ Object (readonly)
Returns the value of attribute dbs.
4 5 6 |
# File 'lib/ffi-snap7/data_structures/data_block_registry.rb', line 4 def dbs @dbs end |
Instance Method Details
#add_variable(ident, address, data_type) ⇒ Object
11 12 13 14 15 |
# File 'lib/ffi-snap7/data_structures/data_block_registry.rb', line 11 def add_variable(ident, address, data_type) db_addr, _, var_addr = address.partition('.') var = Snap7::Variable.new ident, var_addr, data_type db(db_addr).add_variable var end |
#db(db_addr) ⇒ Object
28 29 30 |
# File 'lib/ffi-snap7/data_structures/data_block_registry.rb', line 28 def db(db_addr) @dbs[db_addr] ||= Snap7::DataBlock.new(db_addr) end |
#each(&block) ⇒ Object
33 34 35 |
# File 'lib/ffi-snap7/data_structures/data_block_registry.rb', line 33 def each(&block) sorted_dbs.each &block end |
#find_variable(ident) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/ffi-snap7/data_structures/data_block_registry.rb', line 18 def find_variable(ident) each do |db| found_variable = db.variables.find { |var| var.ident == ident } return found_variable if found_variable end return nil end |
#sorted_dbs ⇒ Object
38 39 40 |
# File 'lib/ffi-snap7/data_structures/data_block_registry.rb', line 38 def sorted_dbs @dbs.values.sort { |a,b| a.number <=> b.number } end |