lens_protocol 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.envrc +2 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +16 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -3
- data/Gemfile.lock +47 -34
- data/README.md +2 -2
- data/examples/oma/R1000_1.oma +213 -213
- data/examples/oma/R1000_2.oma +213 -213
- data/examples/oma/STHKFMT.oma +358 -0
- data/lens_protocol.gemspec +2 -2
- data/lib/lens_protocol/errors.rb +3 -0
- data/lib/lens_protocol/oma/builder.rb +18 -0
- data/lib/lens_protocol/oma/formatter.rb +10 -2
- data/lib/lens_protocol/oma/line.rb +16 -0
- data/lib/lens_protocol/oma/message.rb +5 -59
- data/lib/lens_protocol/oma/parser.rb +17 -9
- data/lib/lens_protocol/oma/record.rb +0 -1
- data/lib/lens_protocol/oma/types/array.rb +21 -0
- data/lib/lens_protocol/oma/types/chiral.rb +31 -0
- data/lib/lens_protocol/oma/types/ignored.rb +15 -0
- data/lib/lens_protocol/oma/types/matrix.rb +17 -0
- data/lib/lens_protocol/oma/types/single.rb +21 -0
- data/lib/lens_protocol/oma/types/trcfmt.rb +77 -0
- data/lib/lens_protocol/oma/types/type.rb +74 -0
- data/lib/lens_protocol/oma/types/values/tracing_dataset.rb +42 -0
- data/lib/lens_protocol/oma/types.rb +81 -79
- data/lib/lens_protocol/oma.rb +1 -1
- data/lib/lens_protocol/version.rb +1 -1
- data/lib/lens_protocol.rb +10 -6
- data/shell.nix +9 -0
- metadata +27 -21
- data/lib/lens_protocol/oma/type/base.rb +0 -97
- data/lib/lens_protocol/oma/type/integer.rb +0 -15
- data/lib/lens_protocol/oma/type/numeric.rb +0 -24
- data/lib/lens_protocol/oma/type/r.rb +0 -17
- data/lib/lens_protocol/oma/type/text.rb +0 -8
- data/lib/lens_protocol/oma/type/trcfmt.rb +0 -30
@@ -0,0 +1,77 @@
|
|
1
|
+
module LensProtocol
|
2
|
+
module OMA
|
3
|
+
module Types
|
4
|
+
class Trcfmt < Type
|
5
|
+
def parse line, next_lines
|
6
|
+
dataset1, next_lines = extract_tracing_dataset [line, *next_lines]
|
7
|
+
dataset2, next_lines = extract_tracing_dataset next_lines
|
8
|
+
|
9
|
+
datasets = [dataset1, dataset2].compact
|
10
|
+
value = [
|
11
|
+
datasets.detect { |ds| ds.side == 'R' },
|
12
|
+
datasets.detect { |ds| ds.side == 'L' }
|
13
|
+
]
|
14
|
+
|
15
|
+
[value, next_lines]
|
16
|
+
end
|
17
|
+
|
18
|
+
def wrap value, message_hash, _label
|
19
|
+
right_side, left_side = value
|
20
|
+
[
|
21
|
+
build_tracing_dataset(right_side, message_hash),
|
22
|
+
build_tracing_dataset(left_side, message_hash)
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
def format label, chiral_value
|
27
|
+
chiral_value.compact.flat_map do |value|
|
28
|
+
[
|
29
|
+
build_line(label, format_values(value.trcfmt_values)),
|
30
|
+
*value.radius_data.each_slice(10).map { |vs| build_line('R', format_values(vs)) }
|
31
|
+
]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def extract_tracing_dataset lines
|
38
|
+
line, *next_lines = lines.drop_while { |line| line.label != 'TRCFMT' }
|
39
|
+
|
40
|
+
if line
|
41
|
+
trcfmt_values = parse_values line.data
|
42
|
+
|
43
|
+
radius_data = next_lines
|
44
|
+
.take_while { |line| line.label == 'R' }
|
45
|
+
.flat_map { |line| parse_radius_data line.data, trcfmt_values[0] }
|
46
|
+
|
47
|
+
dataset = Values::TracingDataset.new(trcfmt_values: trcfmt_values, radius_data: radius_data)
|
48
|
+
[dataset, next_lines.drop_while { |line| line.label == 'R' }]
|
49
|
+
else
|
50
|
+
[nil, []]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse_radius_data data, format
|
55
|
+
if format == '1'
|
56
|
+
parse_values data, :integer
|
57
|
+
else
|
58
|
+
data
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def build_tracing_dataset value, message_hash
|
63
|
+
return unless value
|
64
|
+
|
65
|
+
_, _, _, side, = value
|
66
|
+
raise ValidationError, "Invalid TRCFMT value '#{value}'" unless %w[L R].include?(side)
|
67
|
+
|
68
|
+
r_values = message_hash['R']
|
69
|
+
raise ValidationError, "Invalid R value '#{r_values}'" unless r_values && r_values.size == 2
|
70
|
+
|
71
|
+
radius_data = r_values[side == 'R' ? 0 : 1]
|
72
|
+
Values::TracingDataset.new(trcfmt_values: value, radius_data: radius_data)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module LensProtocol
|
2
|
+
module OMA
|
3
|
+
module Types
|
4
|
+
class Type
|
5
|
+
def initialize value_type: :string, decimals: nil
|
6
|
+
@value_type = value_type
|
7
|
+
@decimals = decimals
|
8
|
+
end
|
9
|
+
|
10
|
+
# Receives the current line and the lines after that.
|
11
|
+
# Must return the parsed value to store on the message, and the array of (possibly filtered) next lines.
|
12
|
+
def parse _line, _next_lines
|
13
|
+
raise NotImplementedError, self
|
14
|
+
end
|
15
|
+
|
16
|
+
# Used when building a message from a hash. Validations may be placed in the subclasses.
|
17
|
+
# TODO The message hash is only used for records like TRCFMT that need to access the R values, but having
|
18
|
+
# the R at the same level in the hash would not allow for building messages with TRCFMT and STHKFMT.
|
19
|
+
def wrap value, _message_hash, _label
|
20
|
+
value
|
21
|
+
end
|
22
|
+
|
23
|
+
# Receives a record label and value.
|
24
|
+
# Must return one line or and array of them.
|
25
|
+
def format _label, _value
|
26
|
+
raise NotImplementedError, self
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def parse_value value, type = @value_type
|
32
|
+
case type
|
33
|
+
when :string
|
34
|
+
value if value != '?'
|
35
|
+
when :integer
|
36
|
+
Integer(value) rescue Float(value).round rescue nil
|
37
|
+
when :numeric
|
38
|
+
Float(value) rescue nil
|
39
|
+
else
|
40
|
+
raise "Value type '#{type}' not supported"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_values data, type = @value_type
|
45
|
+
data.split(';', -1).map { |value| parse_value value, type }
|
46
|
+
end
|
47
|
+
|
48
|
+
def format_value value, type = @value_type
|
49
|
+
return nil unless value
|
50
|
+
|
51
|
+
case type
|
52
|
+
when :string
|
53
|
+
value
|
54
|
+
when :integer
|
55
|
+
value.round
|
56
|
+
when :numeric
|
57
|
+
@decimals ? "%.#{@decimals}f" % value : value
|
58
|
+
else
|
59
|
+
raise "Value type '#{type}' not supported"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def format_values values, type = @value_type
|
64
|
+
values = values.is_a?(::Array) ? values : [values]
|
65
|
+
values.map { |v| format_value v, type }.join(';')
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_line label, data
|
69
|
+
Line.new label: label, data: data
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module LensProtocol
|
2
|
+
module OMA
|
3
|
+
module Types
|
4
|
+
module Values
|
5
|
+
class TracingDataset
|
6
|
+
attr_reader :trcfmt_values, :radius_data
|
7
|
+
|
8
|
+
def initialize trcfmt_values:, radius_data: []
|
9
|
+
@trcfmt_values = trcfmt_values
|
10
|
+
@radius_data = radius_data
|
11
|
+
end
|
12
|
+
|
13
|
+
def side
|
14
|
+
trcfmt_values[3]
|
15
|
+
end
|
16
|
+
|
17
|
+
def format
|
18
|
+
trcfmt_values[0]
|
19
|
+
end
|
20
|
+
|
21
|
+
def side_pos
|
22
|
+
side == 'R' ? 0 : 1
|
23
|
+
end
|
24
|
+
|
25
|
+
# Converts the radius data record values to polar coordinates.
|
26
|
+
def in_polar_coordinates
|
27
|
+
return [] unless recognized_format?
|
28
|
+
radius_data.map.with_index { |r, i| [i * 2 * Math::PI / radius_data.size, r] }
|
29
|
+
end
|
30
|
+
|
31
|
+
def in_rectangular_coordinates
|
32
|
+
in_polar_coordinates.map { |(a, r)| [r * Math.cos(a), r * Math.sin(a)].map { |v| v.round 2 } }
|
33
|
+
end
|
34
|
+
|
35
|
+
def recognized_format?
|
36
|
+
format == '1'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,84 +1,86 @@
|
|
1
1
|
module LensProtocol
|
2
2
|
module OMA
|
3
|
-
TYPES = Hash.new {
|
4
|
-
'ACOAT' =>
|
5
|
-
'ADD' =>
|
6
|
-
'AX' =>
|
7
|
-
'BACK' =>
|
8
|
-
'BCTHK' =>
|
9
|
-
'BEVM' =>
|
10
|
-
'BEVP' =>
|
11
|
-
'BSIZ' =>
|
12
|
-
'BVD' =>
|
13
|
-
'CRIB' =>
|
14
|
-
'CTHICK' =>
|
15
|
-
'CYL' =>
|
16
|
-
'DBL' =>
|
17
|
-
'DIA' =>
|
18
|
-
'DRILLE' =>
|
19
|
-
'ETYP' =>
|
20
|
-
'FCOCIN' =>
|
21
|
-
'FCOCUP' =>
|
22
|
-
'FCSGIN' =>
|
23
|
-
'FCSGUP' =>
|
24
|
-
'FCRV' =>
|
25
|
-
'FED' =>
|
26
|
-
'FPINB' =>
|
27
|
-
'FRNT' =>
|
28
|
-
'FTYP' =>
|
29
|
-
'FWD' =>
|
30
|
-
'GDEPTH' =>
|
31
|
-
'GWIDTH' =>
|
32
|
-
'GRADIENT' =>
|
33
|
-
'HBOX' =>
|
34
|
-
'IPD' =>
|
35
|
-
'LDADD' =>
|
36
|
-
'LDDRAX' =>
|
37
|
-
'LDDRCYL' =>
|
38
|
-
'LDDRSPH' =>
|
39
|
-
'LDNAM' =>
|
40
|
-
'LDNRAX' =>
|
41
|
-
'LDNRCYL' =>
|
42
|
-
'LDNRSPH' =>
|
43
|
-
'LDVEN' =>
|
44
|
-
'LIND' =>
|
45
|
-
'LMATID' =>
|
46
|
-
'LMATTYPE' =>
|
47
|
-
'LNAM' =>
|
48
|
-
'LTYPE' =>
|
49
|
-
'MAXFRT' =>
|
50
|
-
'MBASE' =>
|
51
|
-
'MINFRT' =>
|
52
|
-
'MINEDG' =>
|
53
|
-
'MPD' =>
|
54
|
-
'NPD' =>
|
55
|
-
'OCHT' =>
|
56
|
-
'OPC' =>
|
57
|
-
'OPTFRNT' =>
|
58
|
-
'PANTO' =>
|
59
|
-
'PINB' =>
|
60
|
-
'POLAR' =>
|
61
|
-
'PRVA' =>
|
62
|
-
'PRVM' =>
|
63
|
-
'R' =>
|
64
|
-
'SEGHT' =>
|
65
|
-
'SGOCIN' =>
|
66
|
-
'SGOCUP' =>
|
67
|
-
'SPH' =>
|
68
|
-
'STATUS' =>
|
69
|
-
'THKP' =>
|
70
|
-
'TINT' =>
|
71
|
-
'TRCFMT' =>
|
72
|
-
'VIEWP' =>
|
73
|
-
'VBOX' =>
|
74
|
-
'XSTATUS' =>
|
75
|
-
'ZTILT' =>
|
76
|
-
'_BLANK' =>
|
77
|
-
'_LLVAL' =>
|
78
|
-
'_PRVA1' =>
|
79
|
-
'_PRVA2' =>
|
80
|
-
'_PRVM1' =>
|
81
|
-
'_PRVM2' =>
|
3
|
+
TYPES = Hash.new { Types::Single.new }.merge(
|
4
|
+
'ACOAT' => Types::Chiral.new,
|
5
|
+
'ADD' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
6
|
+
'AX' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
7
|
+
'BACK' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
8
|
+
'BCTHK' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
9
|
+
'BEVM' => Types::Chiral.new(value_type: :integer),
|
10
|
+
'BEVP' => Types::Chiral.new(value_type: :integer),
|
11
|
+
'BSIZ' => Types::Chiral.new(value_type: :integer),
|
12
|
+
'BVD' => Types::Chiral.new(value_type: :integer),
|
13
|
+
'CRIB' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
14
|
+
'CTHICK' => Types::Chiral.new(value_type: :numeric, decimals: 3),
|
15
|
+
'CYL' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
16
|
+
'DBL' => Types::Single.new(value_type: :numeric),
|
17
|
+
'DIA' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
18
|
+
'DRILLE' => Types::Matrix.new,
|
19
|
+
'ETYP' => Types::Single.new(value_type: :integer),
|
20
|
+
'FCOCIN' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
21
|
+
'FCOCUP' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
22
|
+
'FCSGIN' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
23
|
+
'FCSGUP' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
24
|
+
'FCRV' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
25
|
+
'FED' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
26
|
+
'FPINB' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
27
|
+
'FRNT' => Types::Chiral.new(value_type: :numeric, decimals: 3),
|
28
|
+
'FTYP' => Types::Single.new(value_type: :integer),
|
29
|
+
'FWD' => Types::Chiral.new(value_type: :numeric),
|
30
|
+
'GDEPTH' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
31
|
+
'GWIDTH' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
32
|
+
'GRADIENT' => Types::Chiral.new(value_type: :integer),
|
33
|
+
'HBOX' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
34
|
+
'IPD' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
35
|
+
'LDADD' => Types::Chiral.new(value_type: :numeric),
|
36
|
+
'LDDRAX' => Types::Chiral.new(value_type: :numeric),
|
37
|
+
'LDDRCYL' => Types::Chiral.new(value_type: :numeric),
|
38
|
+
'LDDRSPH' => Types::Chiral.new(value_type: :numeric),
|
39
|
+
'LDNAM' => Types::Chiral.new,
|
40
|
+
'LDNRAX' => Types::Chiral.new(value_type: :numeric),
|
41
|
+
'LDNRCYL' => Types::Chiral.new(value_type: :numeric),
|
42
|
+
'LDNRSPH' => Types::Chiral.new(value_type: :numeric),
|
43
|
+
'LDVEN' => Types::Chiral.new,
|
44
|
+
'LIND' => Types::Chiral.new(value_type: :numeric, decimals: 3),
|
45
|
+
'LMATID' => Types::Chiral.new(value_type: :integer),
|
46
|
+
'LMATTYPE' => Types::Chiral.new,
|
47
|
+
'LNAM' => Types::Chiral.new,
|
48
|
+
'LTYPE' => Types::Chiral.new,
|
49
|
+
'MAXFRT' => Types::Chiral.new(value_type: :numeric),
|
50
|
+
'MBASE' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
51
|
+
'MINFRT' => Types::Chiral.new(value_type: :numeric),
|
52
|
+
'MINEDG' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
53
|
+
'MPD' => Types::Chiral.new(value_type: :integer),
|
54
|
+
'NPD' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
55
|
+
'OCHT' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
56
|
+
'OPC' => Types::Chiral.new,
|
57
|
+
'OPTFRNT' => Types::Chiral.new(value_type: :numeric),
|
58
|
+
'PANTO' => Types::Chiral.new(value_type: :integer),
|
59
|
+
'PINB' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
60
|
+
'POLAR' => Types::Chiral.new(value_type: :integer),
|
61
|
+
'PRVA' => Types::Chiral.new(value_type: :numeric, decimals: 1),
|
62
|
+
'PRVM' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
63
|
+
'R' => Types::Ignored.new,
|
64
|
+
'SEGHT' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
65
|
+
'SGOCIN' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
66
|
+
'SGOCUP' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
67
|
+
'SPH' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
68
|
+
'STATUS' => Types::Single.new(value_type: :integer),
|
69
|
+
'THKP' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
70
|
+
'TINT' => Types::Chiral.new,
|
71
|
+
'TRCFMT' => Types::Trcfmt.new,
|
72
|
+
'VIEWP' => Types::Array.new,
|
73
|
+
'VBOX' => Types::Chiral.new(value_type: :numeric, decimals: 2),
|
74
|
+
'XSTATUS' => Types::Matrix.new,
|
75
|
+
'ZTILT' => Types::Chiral.new(value_type: :integer),
|
76
|
+
'_BLANK' => Types::Matrix.new,
|
77
|
+
'_LLVAL' => Types::Chiral.new(value_type: :integer),
|
78
|
+
'_PRVA1' => Types::Chiral.new(value_type: :integer),
|
79
|
+
'_PRVA2' => Types::Chiral.new(value_type: :integer),
|
80
|
+
'_PRVM1' => Types::Chiral.new(value_type: :numeric, decimals: 1),
|
81
|
+
'_PRVM2' => Types::Chiral.new(value_type: :numeric, decimals: 1),
|
82
|
+
'_ETYP2' => Types::Chiral.new(value_type: :integer),
|
83
|
+
'_CTO' => Types::Chiral.new(value_type: :integer)
|
82
84
|
)
|
83
85
|
end
|
84
86
|
end
|
data/lib/lens_protocol/oma.rb
CHANGED
data/lib/lens_protocol.rb
CHANGED
@@ -5,14 +5,18 @@ require 'lens_protocol/version'
|
|
5
5
|
require 'lens_protocol/errors'
|
6
6
|
require 'lens_protocol/oma/record'
|
7
7
|
require 'lens_protocol/oma/message'
|
8
|
-
require 'lens_protocol/oma/type
|
9
|
-
require 'lens_protocol/oma/
|
10
|
-
require 'lens_protocol/oma/
|
11
|
-
require 'lens_protocol/oma/
|
12
|
-
require 'lens_protocol/oma/
|
13
|
-
require 'lens_protocol/oma/
|
8
|
+
require 'lens_protocol/oma/types/type'
|
9
|
+
require 'lens_protocol/oma/types/single'
|
10
|
+
require 'lens_protocol/oma/types/array'
|
11
|
+
require 'lens_protocol/oma/types/matrix'
|
12
|
+
require 'lens_protocol/oma/types/chiral'
|
13
|
+
require 'lens_protocol/oma/types/ignored'
|
14
|
+
require 'lens_protocol/oma/types/trcfmt'
|
15
|
+
require 'lens_protocol/oma/types/values/tracing_dataset'
|
14
16
|
require 'lens_protocol/oma/types'
|
17
|
+
require 'lens_protocol/oma/line'
|
15
18
|
require 'lens_protocol/oma/parser'
|
16
19
|
require 'lens_protocol/oma/formatter'
|
20
|
+
require 'lens_protocol/oma/builder'
|
17
21
|
require 'lens_protocol/oma'
|
18
22
|
require 'lens_protocol/svg'
|
data/shell.nix
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lens_protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emmanuel Nicolau
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: sinatra
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,19 +123,19 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: rubocop
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
131
|
+
version: 0.80.0
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
136
|
+
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
138
|
+
version: 0.80.0
|
139
139
|
description: A Ruby parser and builder for the OMA protocol (a.k.a. Data Communication
|
140
140
|
Standard) that was developed by the Lens Processing & Technology Division of The
|
141
141
|
Vision Council for interconnection of optical laboratory equipment.
|
@@ -145,6 +145,7 @@ executables: []
|
|
145
145
|
extensions: []
|
146
146
|
extra_rdoc_files: []
|
147
147
|
files:
|
148
|
+
- ".envrc"
|
148
149
|
- ".gitignore"
|
149
150
|
- ".rspec"
|
150
151
|
- ".rubocop.yml"
|
@@ -166,6 +167,7 @@ files:
|
|
166
167
|
- examples/oma/R360_1.oma
|
167
168
|
- examples/oma/R360_2.oma
|
168
169
|
- examples/oma/R360_3.oma
|
170
|
+
- examples/oma/STHKFMT.oma
|
169
171
|
- examples/oma/TRCFMT6.oma
|
170
172
|
- examples/public/styles.css
|
171
173
|
- examples/svg.rb
|
@@ -174,23 +176,28 @@ files:
|
|
174
176
|
- lib/lens_protocol.rb
|
175
177
|
- lib/lens_protocol/errors.rb
|
176
178
|
- lib/lens_protocol/oma.rb
|
179
|
+
- lib/lens_protocol/oma/builder.rb
|
177
180
|
- lib/lens_protocol/oma/formatter.rb
|
181
|
+
- lib/lens_protocol/oma/line.rb
|
178
182
|
- lib/lens_protocol/oma/message.rb
|
179
183
|
- lib/lens_protocol/oma/parser.rb
|
180
184
|
- lib/lens_protocol/oma/record.rb
|
181
|
-
- lib/lens_protocol/oma/type/base.rb
|
182
|
-
- lib/lens_protocol/oma/type/integer.rb
|
183
|
-
- lib/lens_protocol/oma/type/numeric.rb
|
184
|
-
- lib/lens_protocol/oma/type/r.rb
|
185
|
-
- lib/lens_protocol/oma/type/text.rb
|
186
|
-
- lib/lens_protocol/oma/type/trcfmt.rb
|
187
185
|
- lib/lens_protocol/oma/types.rb
|
186
|
+
- lib/lens_protocol/oma/types/array.rb
|
187
|
+
- lib/lens_protocol/oma/types/chiral.rb
|
188
|
+
- lib/lens_protocol/oma/types/ignored.rb
|
189
|
+
- lib/lens_protocol/oma/types/matrix.rb
|
190
|
+
- lib/lens_protocol/oma/types/single.rb
|
191
|
+
- lib/lens_protocol/oma/types/trcfmt.rb
|
192
|
+
- lib/lens_protocol/oma/types/type.rb
|
193
|
+
- lib/lens_protocol/oma/types/values/tracing_dataset.rb
|
188
194
|
- lib/lens_protocol/svg.rb
|
189
195
|
- lib/lens_protocol/version.rb
|
196
|
+
- shell.nix
|
190
197
|
homepage: https://github.com/eeng/lens_protocol
|
191
198
|
licenses: []
|
192
199
|
metadata: {}
|
193
|
-
post_install_message:
|
200
|
+
post_install_message:
|
194
201
|
rdoc_options: []
|
195
202
|
require_paths:
|
196
203
|
- lib
|
@@ -205,9 +212,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
212
|
- !ruby/object:Gem::Version
|
206
213
|
version: '0'
|
207
214
|
requirements: []
|
208
|
-
|
209
|
-
|
210
|
-
signing_key:
|
215
|
+
rubygems_version: 3.2.26
|
216
|
+
signing_key:
|
211
217
|
specification_version: 4
|
212
218
|
summary: LensProtocol is a Ruby parser and builder for the OMA protocol.
|
213
219
|
test_files: []
|
@@ -1,97 +0,0 @@
|
|
1
|
-
module LensProtocol
|
2
|
-
module OMA
|
3
|
-
module Type
|
4
|
-
class Base
|
5
|
-
def initialize mode: :single_value
|
6
|
-
@mode = mode
|
7
|
-
end
|
8
|
-
|
9
|
-
# Given a line and a message produces a new message with the record(s) corresponding to that line added to the message
|
10
|
-
# @return [Message]
|
11
|
-
def parse line, message
|
12
|
-
label, data = label_and_data line
|
13
|
-
case @mode
|
14
|
-
when :single_value
|
15
|
-
message.add_record label, parse_value(data)
|
16
|
-
when :array_of_values
|
17
|
-
message.add_record_or_concat_values label, parse_values(data)
|
18
|
-
when :chiral
|
19
|
-
message.add_record label, parse_chiral(data)
|
20
|
-
when :matrix_of_values
|
21
|
-
message.add_record_or_insert_values label, parse_values(data)
|
22
|
-
else
|
23
|
-
raise ArgumentError, "Mode #{@mode} not supported"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# @return [Array of lines or a single one]
|
28
|
-
def format record, _message
|
29
|
-
case @mode
|
30
|
-
when :single_value
|
31
|
-
format_line record.label, [format_value(record.value)]
|
32
|
-
when :array_of_values
|
33
|
-
format_line record.label, format_values(record.value)
|
34
|
-
when :chiral
|
35
|
-
format_line record.label, format_chiral(record.value)
|
36
|
-
when :matrix_of_values
|
37
|
-
record.value.map do |value|
|
38
|
-
format_line record.label, format_values(value)
|
39
|
-
end
|
40
|
-
else
|
41
|
-
raise ArgumentError, "Mode #{@mode} not supported"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def label_and_data line
|
48
|
-
label, data = line.split('=', -1)
|
49
|
-
[label, data]
|
50
|
-
end
|
51
|
-
|
52
|
-
def label_and_values line
|
53
|
-
label, data = label_and_data line
|
54
|
-
[label, parse_values(data)]
|
55
|
-
end
|
56
|
-
|
57
|
-
def parse_values data
|
58
|
-
data.split(';', -1).map { |value| parse_value value }
|
59
|
-
end
|
60
|
-
|
61
|
-
def parse_value value
|
62
|
-
value if value != '?'
|
63
|
-
end
|
64
|
-
|
65
|
-
def parse_chiral values
|
66
|
-
make_chiral parse_values values
|
67
|
-
end
|
68
|
-
|
69
|
-
def make_chiral values
|
70
|
-
if values.size <= 1
|
71
|
-
[values[0], values[0]]
|
72
|
-
else
|
73
|
-
values[0..1]
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def format_line label, values
|
78
|
-
"#{label}=#{values.join(';')}"
|
79
|
-
end
|
80
|
-
|
81
|
-
def format_value value
|
82
|
-
value
|
83
|
-
end
|
84
|
-
|
85
|
-
def format_values values
|
86
|
-
values = values.is_a?(Array) ? values : [values]
|
87
|
-
values.map { |v| format_value(v) }
|
88
|
-
end
|
89
|
-
|
90
|
-
def format_chiral value
|
91
|
-
return [] if Array(value).select(&:present?).empty?
|
92
|
-
make_chiral format_values value
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|