File tree 3 files changed +17
-6
lines changed
3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -29,13 +29,15 @@ def << value
29
29
# The default urgency level if not specified.
30
30
DEFAULT_URGENCY = 3
31
31
32
- # Returns the urgency level if specified. 0 is the highest priority, and 7 is the lowest.
32
+ # The urgency level, if specified using `u=`. 0 is the highest priority, and 7 is the lowest.
33
+ #
34
+ # Note that when duplicate Dictionary keys are encountered, all but the last instance are ignored.
33
35
#
34
36
# @returns [Integer | Nil] the urgency level if specified, or `nil` if not present.
35
37
def urgency ( default = DEFAULT_URGENCY )
36
- if value = self . find { |value | value . start_with? ( "u=" ) }
38
+ if value = self . reverse_find { |value | value . start_with? ( "u=" ) }
37
39
_ , level = value . split ( "=" , 2 )
38
- return level . to_i
40
+ return Integer ( level )
39
41
end
40
42
41
43
return default
Original file line number Diff line number Diff line change @@ -39,6 +39,16 @@ def << value
39
39
def to_s
40
40
join ( "," )
41
41
end
42
+
43
+ protected
44
+
45
+ def reverse_find ( &block )
46
+ reverse_each do |value |
47
+ return value if block . call ( value )
48
+ end
49
+
50
+ return nil
51
+ end
42
52
end
43
53
end
44
54
end
Original file line number Diff line number Diff line change 55
55
end
56
56
57
57
with "u=2, u=5" do
58
- it "prioritizes the first urgency directive" do
58
+ it "prioritizes the last urgency directive" do
59
59
expect ( header ) . to have_attributes (
60
- # First occurrence takes precedence
61
- urgency : be == 2 ,
60
+ urgency : be == 5 ,
62
61
)
63
62
end
64
63
end
You can’t perform that action at this time.
0 commit comments