@@ -14,34 +14,47 @@ class Html2rssFacade
1414
1515 attr_reader :feed_config , :typecast_params
1616
17- ##
18- # @param name [String] the name of a html2rss-configs provided config.
19- # @param typecast_params [Object]
20- # @return [String] the serialized RSS feed
21- def self . from_config ( name , typecast_params , &)
22- feed_config = Html2rss ::Configs . find_by_name ( name )
23- new ( feed_config , typecast_params ) . feed ( &)
24- end
17+ class << self
18+ ##
19+ # @param name [String] the name of a html2rss-configs provided config.
20+ # @param typecast_params [Object]
21+ # @return [String] the serialized RSS feed
22+ def from_config ( name , typecast_params , &)
23+ feed_config = Html2rss ::Configs . find_by_name ( name )
24+ new ( feed_config , typecast_params ) . feed ( &)
25+ end
2526
26- ##
27- # @param name [String] the name of a feed in the file `config/feeds.yml`
28- # @param typecast_params [Object]
29- # @return [String] the serialized RSS feed
30- def self . from_local_config ( name , typecast_params , &)
31- feed_config = LocalConfig . find ( name )
32- new ( feed_config , typecast_params ) . feed ( &)
33- end
27+ ##
28+ # @param name [String] the name of a feed in the file `config/feeds.yml`
29+ # @param typecast_params [Object]
30+ # @return [String] the serialized RSS feed
31+ def from_local_config ( name , typecast_params , &)
32+ feed_config = LocalConfig . find ( name )
33+ new ( feed_config , typecast_params ) . feed ( &)
34+ end
3435
35- ##
36- # @param feed_config [Hash<Symbol, Object>]
37- # @param typecast_params [Object]
38- # @param global_config [Hash<Symbol, Object>]
39- # @return [Html2rss::Config]
40- # @raise [Roda::RodaPlugins::TypecastParams::Error]
41- def self . feed_config_to_config ( feed_config , typecast_params , global_config : LocalConfig . global )
42- dynamic_params = Html2rss ::Config ::Channel . required_params_for_config ( feed_config [ :channel ] )
43- . to_h { |name | [ name , typecast_params . str! ( name ) ] }
44- Html2rss ::Config . new ( feed_config , global_config , dynamic_params )
36+ ##
37+ # @param feed_config [Hash<Symbol, Object>]
38+ # @param typecast_params [Object]
39+ # @param global_config [Hash<Symbol, Object>]
40+ # @return [Html2rss::Config]
41+ # @raise [Roda::RodaPlugins::TypecastParams::Error]
42+ def feed_config_to_config ( feed_config , typecast_params , global_config : LocalConfig . global )
43+ params = required_params_for_config ( feed_config [ :channel ] )
44+ . to_h { |name | [ name , typecast_params . str! ( name ) ] }
45+
46+ config = global_config . merge ( feed_config )
47+ config [ :params ] = params if params . any?
48+ config
49+ end
50+
51+ private
52+
53+ def required_params_for_config ( config )
54+ config . each_with_object ( Set . new ) do |( _ , value ) , required_params |
55+ required_params . merge ( value . scan ( /%<(\w +)>[s|d]/ ) . flatten ) if value . is_a? ( String )
56+ end
57+ end
4558 end
4659
4760 ##
0 commit comments