Class: Upperkut::Item
- Inherits:
-
Object
- Object
- Upperkut::Item
- Defined in:
- lib/upperkut/item.rb
Instance Attribute Summary collapse
-
#enqueued_at ⇒ Object
readonly
Returns the value of attribute enqueued_at.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #body ⇒ Object
-
#initialize(body, enqueued_at = nil) ⇒ Item
constructor
A new instance of Item.
- #key?(key) ⇒ Boolean
- #to_json ⇒ Object
Constructor Details
#initialize(body, enqueued_at = nil) ⇒ Item
Returns a new instance of Item.
5 6 7 8 9 10 |
# File 'lib/upperkut/item.rb', line 5 def initialize(body, enqueued_at = nil) raise ArgumentError, 'Body should be a Hash' unless body.is_a?(Hash) @body = body @enqueued_at = enqueued_at || Time.now.utc.to_i end |
Instance Attribute Details
#enqueued_at ⇒ Object (readonly)
Returns the value of attribute enqueued_at.
3 4 5 |
# File 'lib/upperkut/item.rb', line 3 def enqueued_at @enqueued_at end |
Class Method Details
.from_json(item_json) ⇒ Object
35 36 37 38 |
# File 'lib/upperkut/item.rb', line 35 def self.from_json(item_json) hash = JSON.parse(item_json) new(hash['body'], hash['enqueued_at']) end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 |
# File 'lib/upperkut/item.rb', line 12 def [](key) @body[key] end |
#[]=(key, value) ⇒ Object
16 17 18 |
# File 'lib/upperkut/item.rb', line 16 def []=(key, value) @body[key] = value end |
#body ⇒ Object
24 25 26 |
# File 'lib/upperkut/item.rb', line 24 def body @body end |
#key?(key) ⇒ Boolean
20 21 22 |
# File 'lib/upperkut/item.rb', line 20 def key?(key) @body.key?(key) end |
#to_json ⇒ Object
28 29 30 31 32 33 |
# File 'lib/upperkut/item.rb', line 28 def to_json JSON.generate( 'body' => @body, 'enqueued_at' => @enqueued_at ) end |