Module: Simatic::Types
- Defined in:
- lib/simatic/types.rb,
lib/simatic/types/int.rb,
lib/simatic/types/bool.rb,
lib/simatic/types/byte.rb,
lib/simatic/types/char.rb,
lib/simatic/types/dint.rb,
lib/simatic/types/real.rb,
lib/simatic/types/word.rb,
lib/simatic/types/dword.rb,
lib/simatic/types/s5_time.rb,
lib/simatic/types/iec_date.rb,
lib/simatic/types/iec_time.rb,
lib/simatic/types/s7_string.rb,
lib/simatic/types/time_of_day.rb,
lib/simatic/types/simatic_type.rb,
lib/simatic/types/date_and_time.rb,
lib/simatic/types/simatic_simple_type.rb
Defined Under Namespace
Classes: Bool, Byte, Char, DateAndTime, Dint, Dword, IECDate, IECTime, Int, Real, S5time, S7String, SimaticSimpleType, SimaticType, TimeOfDay, Word
Class Method Summary
collapse
Class Method Details
.avaliable ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/simatic/types.rb', line 18
def self.avaliable
[:bool,
:byte,
:char,
:date_and_time,
:dint,
:dword,
:iec_date,
:iec_time,
:int,
:real,
:s5_time,
:s7_string,
:time_of_day,
:word]
end
|
.get(value, type) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/simatic/types.rb', line 73
def self.get value, type
raw = nil
parser = case type.to_sym
when :bool
if value.kind_of? String
if value == '0'
raw = false
elsif value.downcase == 'false'
raw = false
else
raw = value.to_i rescue value
end
end
Bool
when :byte
raw = value.to_i if value.kind_of? String
Byte
when :char
Char
when :date_and_time
raw = Time.parse value if value.kind_of? String
DateAndTime
when :dint
raw = value.to_i if value.kind_of? String
Dint
when :dword
raw = value.to_i if value.kind_of? String
Dword
when :iec_date
raw = Date.parse value if value.kind_of? String
IECDate
when :iec_time
raw = value.to_f if value.kind_of? String
IECTime
when :int
raw = value.to_i if value.kind_of? String
Int
when :real
raw = value.to_f if value.kind_of? String
Real
when :s5_time
raw = value.to_f if value.kind_of? String
S5Time
when :s7_string
S7String
when :time_of_day
raw = value.to_f if value.kind_of? String
TimeOfDay
when :word
raw = value.to_i if value.kind_of? String
Word
when :auto
return value
else
nil
end
raise "Unknown type #{type}" if parser.nil?
parser.new(raw) if parser
end
|
.parse(raw, type) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/simatic/types.rb', line 35
def self.parse raw, type
parser = case type.to_sym
when :bool
Bool
when :byte
Byte
when :char
Char
when :date_and_time
DateAndTime
when :dint
Dint
when :dword
Dword
when :iec_date
IECDate
when :iec_time
IECTime
when :int
Int
when :real
Real
when :s5_time
S5Time
when :s7_string
S7String
when :time_of_day
TimeOfDay
when :word
Word
else
nil
end
raise "Unknown type #{type}" if parser.nil?
parser.parse raw if parser
end
|