2019-03-22 17:41:39 +00:00
|
|
|
# Retrieves a value from match data given its key/label.
|
2019-03-22 17:53:20 +00:00
|
|
|
def match_data_value_with_key(match_data_values, key)
|
|
|
|
labeled_value = match_data_values.find { |v| v.label == key }
|
2019-03-22 17:41:39 +00:00
|
|
|
raise "#{key} is missing" unless labeled_value
|
|
|
|
labeled_value.value
|
2019-03-07 01:40:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Retrieves the string representation and base value
|
2019-03-22 17:41:39 +00:00
|
|
|
# from a `Spectator::Matchers::PrefixedMatchDataValue` (or similar)
|
|
|
|
# in the values returned by `Spectator::Matchers::MatchData#values`.
|
2019-03-22 17:53:20 +00:00
|
|
|
def match_data_value_sans_prefix(match_data_values, key)
|
|
|
|
prefix = match_data_value_with_key(match_data_values, key)
|
|
|
|
{to_s: prefix.to_s, value: prefix.value}
|
2019-03-07 01:40:57 +00:00
|
|
|
end
|
2019-03-22 17:41:39 +00:00
|
|
|
|
|
|
|
# Check whether match data has a value with a specified key/label.
|
2019-03-22 17:53:20 +00:00
|
|
|
def match_data_has_key?(match_data_values, key)
|
|
|
|
found = match_data_values.find { |v| v.label == key }
|
2019-03-22 17:41:39 +00:00
|
|
|
!!found
|
|
|
|
end
|