Class: Skiptorium::BaseSource
- Inherits:
-
Object
- Object
- Skiptorium::BaseSource
- Defined in:
- lib/skiptorium/base_source.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Instance Method Summary collapse
- #apply_filter(stream) ⇒ Object
- #fetch ⇒ Array<Article>
- #fetch_latest ⇒ Object
-
#initialize(config) ⇒ BaseSource
constructor
A new instance of BaseSource.
Constructor Details
#initialize(config) ⇒ BaseSource
Returns a new instance of BaseSource.
5 6 7 8 9 |
# File 'lib/skiptorium/base_source.rb', line 5 def initialize(config) @config = config @limit = config['limit'] || 10 @filter = config['filter'] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/skiptorium/base_source.rb', line 3 def config @config end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
3 4 5 |
# File 'lib/skiptorium/base_source.rb', line 3 def limit @limit end |
Instance Method Details
#apply_filter(stream) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/skiptorium/base_source.rb', line 21 def apply_filter(stream) return stream unless @filter stream.select do |article| pass = @filter.all? do |name, opts| case name when 'front_matter' opts.all? do |k, v| article.front_matter(k.strip) == v.to_s.strip end else raise "Invalid filter #{name}: #{opts.inspect}" end end # puts " article \"#{article.title}\" pass=#{pass}" pass end end |
#fetch ⇒ Array<Article>
12 13 14 |
# File 'lib/skiptorium/base_source.rb', line 12 def fetch raise NotImplementedError, "#{self.class} must implement #fetch_latest" end |
#fetch_latest ⇒ Object
16 17 18 19 |
# File 'lib/skiptorium/base_source.rb', line 16 def fetch_latest filtered = apply_filter(fetch) filtered.first(@limit) end |