Class: Xapian::Indexer::Resource
- Inherits:
-
Object
- Object
- Xapian::Indexer::Resource
- Defined in:
- lib/xapian/indexer/resource.rb
Overview
Represents a resource that will be indexed
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#content ⇒ Object
The data that will be indexed.
- #content? ⇒ Boolean
- #fetch! ⇒ Object
- #fetched? ⇒ Boolean
- #fresh?(at = Time.now) ⇒ Boolean
-
#initialize(name, controller, values = {}) ⇒ Resource
constructor
A new instance of Resource.
- #links ⇒ Object
- #name_digest ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, controller, values = {}) ⇒ Resource
Returns a new instance of Resource.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/xapian/indexer/resource.rb', line 87 def initialize(name, controller, values = {}) @name = name @controller = controller @fetched_on = values[:fetched_on] @status = values[:status] @header = values[:header] @body = values[:body] @metadata = values[:metadata] end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
101 102 103 |
# File 'lib/xapian/indexer/resource.rb', line 101 def body @body end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
100 101 102 |
# File 'lib/xapian/indexer/resource.rb', line 100 def header @header end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
102 103 104 |
# File 'lib/xapian/indexer/resource.rb', line 102 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
98 99 100 |
# File 'lib/xapian/indexer/resource.rb', line 98 def name @name end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
99 100 101 |
# File 'lib/xapian/indexer/resource.rb', line 99 def status @status end |
Instance Method Details
#content ⇒ Object
The data that will be indexed
116 117 118 |
# File 'lib/xapian/indexer/resource.rb', line 116 def content [@metadata[:content] || @body, @metadata[:title], @metadata[:description], @metadata[:keywords]].compact.join(" ") end |
#content? ⇒ Boolean
157 158 159 |
# File 'lib/xapian/indexer/resource.rb', line 157 def content? @body != nil end |
#fetch! ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/xapian/indexer/resource.rb', line 143 def fetch! @controller.load(self) do |status, header, body, | @fetched_on = Time.now @status = status @header = header @body = body @metadata = end end |
#fetched? ⇒ Boolean
153 154 155 |
# File 'lib/xapian/indexer/resource.rb', line 153 def fetched? @fetched_on != nil end |
#fresh?(at = Time.now) ⇒ Boolean
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/xapian/indexer/resource.rb', line 124 def fresh?(at = Time.now) cache_control = @header['cache-control'] || "" fetched_age = @header['age'] || "" max_age = 3600 if cache_control.match(/max-age=([0-9]+)/) max_age = $1.to_i if fetched_age.match(/([0-9]+)/) max_age -= $1.to_i end end age = at - @fetched_on # If the page is younger than the max_age the page can be considered fresh. return age < max_age end |
#links ⇒ Object
120 121 122 |
# File 'lib/xapian/indexer/resource.rb', line 120 def links @metadata[:links] if @metadata end |
#name_digest ⇒ Object
161 162 163 |
# File 'lib/xapian/indexer/resource.rb', line 161 def name_digest "Q" + Digest::MD5.hexdigest(@name) end |
#to_hash ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/xapian/indexer/resource.rb', line 104 def to_hash { :fetched_on => @fetched_on, :name => @name, :status => @status, :header => @header, :body => @body, :metadata => @metadata } end |