Class: ConsadoleAggregator::News::Site
- Inherits:
-
Object
- Object
- ConsadoleAggregator::News::Site
- Defined in:
- lib/consadole_aggregator/news.rb
Constant Summary collapse
- STORE_NAME =
'updated.pstore'
- STORAGE_ELEMENT_SIZE =
200
Instance Attribute Summary collapse
-
#article_filter ⇒ Object
writeonly
Sets the attribute article_filter.
-
#article_parser ⇒ Object
writeonly
Sets the attribute article_parser.
-
#list_parser ⇒ Object
writeonly
Sets the attribute list_parser.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resource ⇒ Object
writeonly
Sets the attribute resource.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name) ⇒ Site
constructor
A new instance of Site.
- #update ⇒ Object
- #updated ⇒ Object
Constructor Details
#initialize(name) ⇒ Site
Returns a new instance of Site.
61 62 63 |
# File 'lib/consadole_aggregator/news.rb', line 61 def initialize name @name = name end |
Instance Attribute Details
#article_filter=(value) ⇒ Object (writeonly)
Sets the attribute article_filter
58 59 60 |
# File 'lib/consadole_aggregator/news.rb', line 58 def article_filter=(value) @article_filter = value end |
#article_parser=(value) ⇒ Object (writeonly)
Sets the attribute article_parser
58 59 60 |
# File 'lib/consadole_aggregator/news.rb', line 58 def article_parser=(value) @article_parser = value end |
#list_parser=(value) ⇒ Object (writeonly)
Sets the attribute list_parser
58 59 60 |
# File 'lib/consadole_aggregator/news.rb', line 58 def list_parser=(value) @list_parser = value end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
59 60 61 |
# File 'lib/consadole_aggregator/news.rb', line 59 def name @name end |
#resource=(value) ⇒ Object (writeonly)
Sets the attribute resource
58 59 60 |
# File 'lib/consadole_aggregator/news.rb', line 58 def resource=(value) @resource = value end |
Class Method Details
.store ⇒ Object
51 52 53 |
# File 'lib/consadole_aggregator/news.rb', line 51 def store @store ||= PStore.new(File.join(ConsadoleAggregator.root_dir, STORE_NAME)) end |
Instance Method Details
#update ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/consadole_aggregator/news.rb', line 69 def update resource = @resource.call list = @list_parser.call(resource).to_a list.select! &@article_filter if @article_filter list.map! &@article_parser if @article_parser list.reject! { |article| updated.include?(article) } list.each { |article| begin yield article if block_given? add_updated article ConsadoleAggregator.logger.info('%s: %s'%[name, article]) rescue ConsadoleAggregator.logger.error('%s: %s'%[name, $!]) end } rescue ConsadoleAggregator.logger.error('%s: %s'%[name, $!]) end |
#updated ⇒ Object
65 66 67 |
# File 'lib/consadole_aggregator/news.rb', line 65 def updated @updated ||= self.class.store.transaction { |s| s.fetch(name, []) } end |