Class: ConsadoleAggregator::News::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/consadole_aggregator/news.rb

Constant Summary collapse

STORE_NAME =
'updated.pstore'
STORAGE_ELEMENT_SIZE =
200

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute article_filter to.



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

Parameters:

  • value

    the value to set the attribute article_parser to.



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

Parameters:

  • value

    the value to set the attribute list_parser to.



58
59
60
# File 'lib/consadole_aggregator/news.rb', line 58

def list_parser=(value)
  @list_parser = value
end

#nameObject (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

Parameters:

  • value

    the value to set the attribute resource to.



58
59
60
# File 'lib/consadole_aggregator/news.rb', line 58

def resource=(value)
  @resource = value
end

Class Method Details

.storeObject



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

#updateObject



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

#updatedObject



65
66
67
# File 'lib/consadole_aggregator/news.rb', line 65

def updated
  @updated ||= self.class.store.transaction { |s| s.fetch(name, []) }
end