Class: HTTPAttack::Items::Base
- Inherits:
-
Object
- Object
- HTTPAttack::Items::Base
- Defined in:
- lib/httpattack/items/base.rb
Instance Attribute Summary collapse
-
#stats ⇒ Object
readonly
Holds the remote response as the Item
stats
.
Class Method Summary collapse
Instance Method Summary collapse
-
#reload_stats(uri = stats_url) ⇒ Object
Parses the JSON response from the
uri
(which can be a a path or URL) and returns it as a hash. -
#reload_stats!(*args) ⇒ Object
Loads
@stats
with the JSON response through#reload_stats
. -
#stat ⇒ Object
This is the strength of the Item and must be overridden in a subclass.
-
#stats_url ⇒ Object
This is the URL where the JSON will come from.
Instance Attribute Details
#stats ⇒ Object (readonly)
Holds the remote response as the Item stats
.
9 10 11 |
# File 'lib/httpattack/items/base.rb', line 9 def stats @stats end |
Class Method Details
.desc ⇒ Object
51 52 53 |
# File 'lib/httpattack/items/base.rb', line 51 def desc 'A basic item.' end |
.name ⇒ Object
47 48 49 |
# File 'lib/httpattack/items/base.rb', line 47 def name self.to_s.split('::').last end |
Instance Method Details
#reload_stats(uri = stats_url) ⇒ Object
Parses the JSON response from the uri
(which can be a a path or URL) and returns it as a hash.
On an error (exception), returns a hash like:
{ 'error' => error. }
29 30 31 32 33 34 35 |
# File 'lib/httpattack/items/base.rb', line 29 def reload_stats(uri = stats_url) begin JSON.parse(open(uri).read) rescue => error {'error' => error.} end end |
#reload_stats!(*args) ⇒ Object
Loads @stats
with the JSON response through #reload_stats
.
38 39 40 |
# File 'lib/httpattack/items/base.rb', line 38 def reload_stats!(*args) @stats = self.reload_stats(*args) end |
#stat ⇒ Object
This is the strength of the Item and must be overridden in a subclass. It should return an Integer (or Float).
14 15 16 |
# File 'lib/httpattack/items/base.rb', line 14 def stat raise MustOverrideMethod end |
#stats_url ⇒ Object
This is the URL where the JSON will come from. Must be overridden in a subclassed Item.
20 21 22 |
# File 'lib/httpattack/items/base.rb', line 20 def stats_url raise MustOverrideMethod end |