File tree Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -29,13 +29,15 @@ def << value
2929 # The default urgency level if not specified.
3030 DEFAULT_URGENCY = 3
3131
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.
3335 #
3436 # @returns [Integer | Nil] the urgency level if specified, or `nil` if not present.
3537 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=" ) }
3739 _ , level = value . split ( "=" , 2 )
38- return level . to_i
40+ return Integer ( level )
3941 end
4042
4143 return default
Original file line number Diff line number Diff line change @@ -39,6 +39,16 @@ def << value
3939 def to_s
4040 join ( "," )
4141 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
4252 end
4353 end
4454 end
Original file line number Diff line number Diff line change 5555 end
5656
5757 with "u=2, u=5" do
58- it "prioritizes the first urgency directive" do
58+ it "prioritizes the last urgency directive" do
5959 expect ( header ) . to have_attributes (
60- # First occurrence takes precedence
61- urgency : be == 2 ,
60+ urgency : be == 5 ,
6261 )
6362 end
6463 end
You can’t perform that action at this time.
0 commit comments