class Item

Attributes

colour[RW]
description[RW]
id[RW]
level[RW]
name[RW]

Public Class Methods

all(credentials) click to toggle source
# File lib/minitest/game/item.rb, line 18
def all(credentials)
  options = { headers: { "Content-Type" => "application/json" } }
  url = NagaApiClient.BASE_URL + "items?" + "authentication_token=" + credentials[:authentication_token] + "&email=" + credentials[:email]
  response = HTTParty.get(url, options)
  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) click to toggle source
# File lib/minitest/game/item.rb, line 38
def drop(credentials)
  options = { headers: { "Content-Type" => "application/json" } }
  url = NagaApiClient.BASE_URL + "items/drop/?authentication_token=" + credentials[:authentication_token] + "&email=" + credentials[:email]
  response = HTTParty.get(url, options)
  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) click to toggle source
# File lib/minitest/game/item.rb, line 30
def get(name, credentials)
  options = { 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, options)
  i = response.parsed_response["item"]
  item = Item.new(i["id"], i["name"], i["description"], i["level"], i["colour"])
end
new(id, name, description, level, colour) click to toggle source
# 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
starter(credentials) click to toggle source
# File lib/minitest/game/item.rb, line 50
def starter(credentials)
  options = { headers: { "Content-Type" => "application/json" } }
  url = NagaApiClient.BASE_URL + "items/starter?" + "authentication_token=" + credentials[:authentication_token] + "&email=" + credentials[:email]
  response = HTTParty.get(url, options)
  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

Public Instance Methods

to_s() click to toggle source
# 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