-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.rb
45 lines (41 loc) · 1.16 KB
/
converter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
module AdventOfCode
module Puzzles2023
module Day05
##
# Class for converting values from source to destination.
class Converter
##
# @return [Symbol] source of the conversion
attr_reader :source
##
# @return [Symbol] destination of the conversion
attr_reader :destination
##
# @param source [Symbol] source of the conversion
# @param destination [Symbol] destination of the conversion
# @param relations [Array<Relation>] array of relations
def initialize(source:, destination:, relations:)
@source = source
@destination = destination
@relations = relations
end
##
# Convert a value from source to destination.
#
# @param value [Integer] value to convert
#
# @return [Integer] converted value
def convert(value:)
# Find value in maps
@relations.each do |relation|
if (result = relation.convert(value:))
return result
end
end
value
end
end
end
end
end