Class: ReevooMark::Document
- Inherits:
-
Object
- Object
- ReevooMark::Document
- Defined in:
- lib/reevoomark/document.rb
Defined Under Namespace
Modules: Factory
Instance Attribute Summary collapse
-
#age ⇒ Object
readonly
Returns the value of attribute age.
-
#counts ⇒ Object
readonly
Returns the value of attribute counts.
-
#max_age ⇒ Object
readonly
Returns the value of attribute max_age.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #===(other) ⇒ Object
- #any? ⇒ Boolean
- #best_price ⇒ Object
- #body ⇒ Object (also: #render)
- #content_values ⇒ Object
- #conversation_count ⇒ Object
- #expired?(now = nil) ⇒ Boolean
- #identity_values ⇒ Object
-
#initialize(time, max_age, age, status_code, body, counts) ⇒ Document
constructor
A new instance of Document.
- #is_valid? ⇒ Boolean
- #offer_count ⇒ Object
- #revalidated_for(max_age) ⇒ Object
- #review_count ⇒ Object
Constructor Details
#initialize(time, max_age, age, status_code, body, counts) ⇒ Document
Returns a new instance of Document.
12 13 14 15 16 |
# File 'lib/reevoomark/document.rb', line 12 def initialize(time, max_age, age, status_code, body, counts) @time, @max_age, @age = time, max_age, age @status_code, @body = status_code, body @counts = counts end |
Instance Attribute Details
#age ⇒ Object (readonly)
Returns the value of attribute age.
2 3 4 |
# File 'lib/reevoomark/document.rb', line 2 def age @age end |
#counts ⇒ Object (readonly)
Returns the value of attribute counts.
2 3 4 |
# File 'lib/reevoomark/document.rb', line 2 def counts @counts end |
#max_age ⇒ Object (readonly)
Returns the value of attribute max_age.
2 3 4 |
# File 'lib/reevoomark/document.rb', line 2 def max_age @max_age end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
2 3 4 |
# File 'lib/reevoomark/document.rb', line 2 def status_code @status_code end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
2 3 4 |
# File 'lib/reevoomark/document.rb', line 2 def time @time end |
Class Method Details
.error ⇒ Object
8 9 10 |
# File 'lib/reevoomark/document.rb', line 8 def self.error ReevooMark::Document::Factory.new_error_document end |
.from_response(response) ⇒ Object
4 5 6 |
# File 'lib/reevoomark/document.rb', line 4 def self.from_response(response) ReevooMark::Document::Factory.from_response(response) end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 |
# File 'lib/reevoomark/document.rb', line 26 def == other identity_values == other.identity_values end |
#===(other) ⇒ Object
30 31 32 |
# File 'lib/reevoomark/document.rb', line 30 def === other content_values == other.content_values end |
#any? ⇒ Boolean
34 35 36 |
# File 'lib/reevoomark/document.rb', line 34 def any? review_count > 0 end |
#best_price ⇒ Object
50 51 52 |
# File 'lib/reevoomark/document.rb', line 50 def best_price @counts[:best_price] end |
#body ⇒ Object Also known as: render
58 59 60 61 62 63 64 |
# File 'lib/reevoomark/document.rb', line 58 def body if is_valid? @body else "" end end |
#content_values ⇒ Object
22 23 24 |
# File 'lib/reevoomark/document.rb', line 22 def content_values [@status_code, @body, @counts] end |
#conversation_count ⇒ Object
46 47 48 |
# File 'lib/reevoomark/document.rb', line 46 def conversation_count @counts[:conversation_count] end |
#expired?(now = nil) ⇒ Boolean
68 69 70 71 |
# File 'lib/reevoomark/document.rb', line 68 def expired?(now = nil) now ||= Time.now max_age < current_age(now) end |
#identity_values ⇒ Object
18 19 20 |
# File 'lib/reevoomark/document.rb', line 18 def identity_values [current_age(0), @content_values] end |
#is_valid? ⇒ Boolean
54 55 56 |
# File 'lib/reevoomark/document.rb', line 54 def is_valid? status_code < 500 end |
#offer_count ⇒ Object
42 43 44 |
# File 'lib/reevoomark/document.rb', line 42 def offer_count @counts[:offer_count] end |
#revalidated_for(max_age) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/reevoomark/document.rb', line 73 def revalidated_for(max_age) ReevooMark::Document.new( Time.now.to_i, max_age || @max_age, 0, @status_code, @body, @counts ) end |
#review_count ⇒ Object
38 39 40 |
# File 'lib/reevoomark/document.rb', line 38 def review_count @counts[:review_count] end |