Class: Feedbook::Feed
- Inherits:
-
Object
- Object
- Feedbook::Feed
- Defined in:
- lib/feedbook/feed.rb
Instance Attribute Summary collapse
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
-
#urls ⇒ Object
readonly
Returns the value of attribute urls.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
-
#fetch ⇒ Array
Fetches and parses all feed and merges into single array.
-
#initialize(opts = {}) ⇒ NilClass
constructor
Initializes new Feed instance for given configuration.
-
#valid? ⇒ NilClass
Validates if given parameters are valid.
Constructor Details
#initialize(opts = {}) ⇒ NilClass
Initializes new Feed instance for given configuration
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/feedbook/feed.rb', line 18 def initialize(opts = {}) @urls = opts.fetch(:urls, '').split @variables = opts.fetch(:variables, {}) @notifications = opts.fetch(:notifications, []).map do |notification| Notification.new( type: notification['type'], template: notification['template'], variables: variables ) end end |
Instance Attribute Details
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
12 13 14 |
# File 'lib/feedbook/feed.rb', line 12 def notifications @notifications end |
#urls ⇒ Object (readonly)
Returns the value of attribute urls.
12 13 14 |
# File 'lib/feedbook/feed.rb', line 12 def urls @urls end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
12 13 14 |
# File 'lib/feedbook/feed.rb', line 12 def variables @variables end |
Instance Method Details
#fetch ⇒ Array
Fetches and parses all feed and merges into single array.
33 34 35 36 37 38 39 |
# File 'lib/feedbook/feed.rb', line 33 def fetch urls .map do |url| parse_feed(Feedjira::Feed.fetch_and_parse(url)) end .inject :+ end |
#valid? ⇒ NilClass
Validates if given parameters are valid
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/feedbook/feed.rb', line 46 def valid? if urls.empty? || urls.any? { |url| url !~ /\A#{URI::regexp}\z/ } raise Errors::InvalidFeedUrlError.new end unless variables.is_a? Hash raise Errors::InvalidVariablesFormatError.new end notifications.each { |notification| notification.valid? } end |