Class: Item
- Inherits:
-
Object
- Object
- Item
- Defined in:
- lib/minitest/game/item.rb
Instance Attribute Summary collapse
-
#colour ⇒ Object
Returns the value of attribute colour.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#level ⇒ Object
Returns the value of attribute level.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .all(credentials) ⇒ Object
- .drop(credentials) ⇒ Object
- .get(name, credentials) ⇒ Object
- .starter(credentials) ⇒ Object
Instance Method Summary collapse
-
#initialize(id, name, description, level, colour) ⇒ Item
constructor
A new instance of Item.
- #to_s ⇒ Object
Constructor Details
#initialize(id, name, description, level, colour) ⇒ Item
Returns a new instance of Item.
8 9 10 11 12 13 14 |
# File 'lib/minitest/game/item.rb', line 8 def initialize(id, name, description, level, colour) @id = id @name = name @description = description @level = level @colour = colour end |
Instance Attribute Details
#colour ⇒ Object
Returns the value of attribute colour.
6 7 8 |
# File 'lib/minitest/game/item.rb', line 6 def colour @colour end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/minitest/game/item.rb', line 4 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/minitest/game/item.rb', line 2 def id @id end |
#level ⇒ Object
Returns the value of attribute level.
5 6 7 |
# File 'lib/minitest/game/item.rb', line 5 def level @level end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/minitest/game/item.rb', line 3 def name @name end |
Class Method Details
.all(credentials) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/minitest/game/item.rb', line 18 def all(credentials) = { headers: { "Content-Type" => "application/json" } } url = NagaApiClient.BASE_URL + "items?" + "authentication_token=" + credentials[:authentication_token] + "&email=" + credentials[:email] response = HTTParty.get(url, ) items = {} response.parsed_response["items"].each do |i| item = Item.new(i["id"], i["name"], i["description"]) items[item.name] = item end items end |
.drop(credentials) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/minitest/game/item.rb', line 38 def drop(credentials) = { headers: { "Content-Type" => "application/json" } } url = NagaApiClient.BASE_URL + "items/drop/?authentication_token=" + credentials[:authentication_token] + "&email=" + credentials[:email] response = HTTParty.get(url, ) i = response.parsed_response["item"] if i item = Item.new(i["id"], i["name"], i["description"], i["level"], i["colour"]) else item = nil end end |
.get(name, credentials) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/minitest/game/item.rb', line 30 def get(name, credentials) = { headers: { "Content-Type" => "application/json" } } url = NagaApiClient.BASE_URL + "items/show/" + URI::encode(name) + "?authentication_token=" + credentials[:authentication_token] + "&email=" + credentials[:email] response = HTTParty.get(url, ) i = response.parsed_response["item"] item = Item.new(i["id"], i["name"], i["description"], i["level"], i["colour"]) end |
.starter(credentials) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/minitest/game/item.rb', line 50 def starter(credentials) = { headers: { "Content-Type" => "application/json" } } url = NagaApiClient.BASE_URL + "items/starter?" + "authentication_token=" + credentials[:authentication_token] + "&email=" + credentials[:email] response = HTTParty.get(url, ) starter_items = {} response.parsed_response["starter_items"].each do |i| item = Item.new(i["id"], i["name"], i["description"]) starter_items[item.name] = item end starter_items end |
Instance Method Details
#to_s ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/minitest/game/item.rb', line 63 def to_s if self colorized_name = self.name.upcase case self.level when 1 colorized_name = colorized_name.colorize(:white) when 2 colorized_name = colorized_name.colorize(:green) when 3 colorized_name = colorized_name.colorize(:blue) when 4 colorized_name = colorized_name.colorize(:light_white) when 5 colorized_name = colorized_name.colorize(:yellow) end say("You found a #{colorized_name}!") say("It has a description: " + self.description + " Level: " + self.level.to_s) end end |