Class: ReevooMark::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/reevoomark/document.rb

Defined Under Namespace

Modules: Factory

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#ageObject (readonly)

Returns the value of attribute age.



2
3
4
# File 'lib/reevoomark/document.rb', line 2

def age
  @age
end

#countsObject (readonly)

Returns the value of attribute counts.



2
3
4
# File 'lib/reevoomark/document.rb', line 2

def counts
  @counts
end

#max_ageObject (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_codeObject (readonly)

Returns the value of attribute status_code.



2
3
4
# File 'lib/reevoomark/document.rb', line 2

def status_code
  @status_code
end

#timeObject (readonly)

Returns the value of attribute time.



2
3
4
# File 'lib/reevoomark/document.rb', line 2

def time
  @time
end

Class Method Details

.errorObject



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

Returns:

  • (Boolean)


34
35
36
# File 'lib/reevoomark/document.rb', line 34

def any?
  review_count > 0
end

#best_priceObject



50
51
52
# File 'lib/reevoomark/document.rb', line 50

def best_price
  @counts[:best_price]
end

#bodyObject 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_valuesObject



22
23
24
# File 'lib/reevoomark/document.rb', line 22

def content_values
  [@status_code, @body, @counts]
end

#conversation_countObject



46
47
48
# File 'lib/reevoomark/document.rb', line 46

def conversation_count
  @counts[:conversation_count]
end

#expired?(now = nil) ⇒ Boolean

Returns:

  • (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_valuesObject



18
19
20
# File 'lib/reevoomark/document.rb', line 18

def identity_values
  [current_age(0), @content_values]
end

#is_valid?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/reevoomark/document.rb', line 54

def is_valid?
  status_code < 500
end

#offer_countObject



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_countObject



38
39
40
# File 'lib/reevoomark/document.rb', line 38

def review_count
  @counts[:review_count]
end