Class: Simatic::Types::SimaticType

Inherits:
Object
  • Object
show all
Defined in:
lib/simatic/types/simatic_type.rb

Direct Known Subclasses

Bool, DateAndTime, S5time, S7String, SimaticSimpleType

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ SimaticType

Returns a new instance of SimaticType.



4
5
6
# File 'lib/simatic/types/simatic_type.rb', line 4

def initialize value
  @value = value
end

Class Method Details

.parse(raw_data) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/simatic/types/simatic_type.rb', line 8

def self.parse raw_data
  if raw_data.kind_of? Array
    # puts "raw_data #{raw_data}"
    raw_data.map { |raw_value| self.parse_one raw_value } 
  else
    parse_one raw_data
  end
end

.parse_one(raw_value) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/simatic/types/simatic_type.rb', line 17

def self.parse_one raw_value
    raw_value_length = raw_value.length
    if raw_value_length != self::LENGTH
      raise "Cant parse, cause raw data length #{raw_value_length} (must be #{self::LENGTH})."
    end
    raw_value
end

Instance Method Details

#serializeObject



25
26
27
28
29
30
31
# File 'lib/simatic/types/simatic_type.rb', line 25

def serialize
  if @value.kind_of? Array
    @value.map { |single_val| self.class.serialize single_val }
  else
    self.class.serialize @value
  end
end