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.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/xapian/indexer/resource.rb', line 92 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.
106 107 108 |
# File 'lib/xapian/indexer/resource.rb', line 106 def body @body end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
105 106 107 |
# File 'lib/xapian/indexer/resource.rb', line 105 def header @header end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
107 108 109 |
# File 'lib/xapian/indexer/resource.rb', line 107 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
103 104 105 |
# File 'lib/xapian/indexer/resource.rb', line 103 def name @name end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
104 105 106 |
# File 'lib/xapian/indexer/resource.rb', line 104 def status @status end |
Instance Method Details
#content ⇒ Object
The data that will be indexed
121 122 123 |
# File 'lib/xapian/indexer/resource.rb', line 121 def content [@metadata[:content] || @body, @metadata[:title], @metadata[:description], @metadata[:keywords]].compact.join(" ") end |
#content? ⇒ Boolean
162 163 164 |
# File 'lib/xapian/indexer/resource.rb', line 162 def content? @body != nil end |
#fetch! ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/xapian/indexer/resource.rb', line 148 def fetch! @controller.load(self) do |status, header, body, | @fetched_on = Time.now @status = status @header = header @body = body @metadata = end end |
#fetched? ⇒ Boolean
158 159 160 |
# File 'lib/xapian/indexer/resource.rb', line 158 def fetched? @fetched_on != nil end |
#fresh?(at = Time.now) ⇒ Boolean
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/xapian/indexer/resource.rb', line 129 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
125 126 127 |
# File 'lib/xapian/indexer/resource.rb', line 125 def links @metadata[:links] if @metadata end |
#name_digest ⇒ Object
166 167 168 |
# File 'lib/xapian/indexer/resource.rb', line 166 def name_digest "Q" + Digest::MD5.hexdigest(@name) end |
#to_hash ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/xapian/indexer/resource.rb', line 109 def to_hash { :fetched_on => @fetched_on, :name => @name, :status => @status, :header => @header, :body => @body, :metadata => @metadata } end |