Class: Trifle::Docs::Harvester::Walker
- Inherits:
-
Object
- Object
- Trifle::Docs::Harvester::Walker
- Defined in:
- lib/trifle/docs/harvester.rb
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#router ⇒ Object
readonly
Returns the value of attribute router.
Instance Method Summary collapse
- #collection_for(url:) ⇒ Object
- #content_for(url:) ⇒ Object
- #gather ⇒ Object
-
#initialize(**keywords) ⇒ Walker
constructor
A new instance of Walker.
- #meta_for(url:) ⇒ Object
- #sitemap ⇒ Object
Constructor Details
#initialize(**keywords) ⇒ Walker
9 10 11 12 13 14 15 16 |
# File 'lib/trifle/docs/harvester.rb', line 9 def initialize(**keywords) @path = keywords.fetch(:path) @harvesters = keywords.fetch(:harvesters) @namespace = keywords.fetch(:namespace) @router = {} gather end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/trifle/docs/harvester.rb', line 7 def namespace @namespace end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/trifle/docs/harvester.rb', line 7 def path @path end |
#router ⇒ Object (readonly)
Returns the value of attribute router.
7 8 9 |
# File 'lib/trifle/docs/harvester.rb', line 7 def router @router end |
Instance Method Details
#collection_for(url:) ⇒ Object
41 42 43 44 45 |
# File 'lib/trifle/docs/harvester.rb', line 41 def collection_for(url:) return sitemap if url.empty? sitemap.dig(*url.split('/')) end |
#content_for(url:) ⇒ Object
47 48 49 |
# File 'lib/trifle/docs/harvester.rb', line 47 def content_for(url:) @router[url].content end |
#gather ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/trifle/docs/harvester.rb', line 18 def gather Dir["#{path}/**/*.*"].each do |file| @harvesters.each do |harvester| sieve = harvester::Sieve.new(path: path, file: file) if sieve.match? @router[sieve.to_url] = harvester::Conveyor.new(file: file, url: sieve.to_url, namespace: namespace) break end end end true end |
#meta_for(url:) ⇒ Object
51 52 53 |
# File 'lib/trifle/docs/harvester.rb', line 51 def (url:) @router[url]. end |
#sitemap ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/trifle/docs/harvester.rb', line 31 def sitemap @sitemap ||= begin mapping = router.keys.each_with_object({}) do |url, out| out[url] = (url: url) end Trifle::Docs::Helper::Tree.new(mapping: mapping). end end |