class Bitcoin::OTC::Rating
Represents a ‘#bitcoin-otc` rating entry.
Attributes
created_at[R]
The rating’s creation date.
@return [DateTime]
id[R]
The rating identifier.
@return [Integer]
notes[R]
The rating’s informational content.
@return [String]
rated_nick[R]
The nick of the user being rated.
@return [String]
rater_nick[R]
The nick of the user who created this rating.
@return [String]
rating[R]
The rating’s numerical value.
@return [Integer]
Public Class Methods
new(id_or_data)
click to toggle source
@overload initialize(id)
@param [Integer] id
@overload initialize(data)
@param [Hash] data
# File lib/bitcoin/otc/rating.rb, line 13 def initialize(id_or_data) case id_or_data when Hash id_or_data.each do |attr, value| case attr.to_sym when :id, :rating value = value.to_i when :created_at value = DateTime.strptime(value, '%s') unless value.is_a?(DateTime) end self.instance_variable_set("@#{attr}", value) end when Integer, String @id = id_or_data.to_i else raise TypeError, "expected an Integer or Hash, but got #{id_or_data.inspect}" end end
Public Instance Methods
rated()
click to toggle source
Returns the account of the user being rated.
@return [Account]
# File lib/bitcoin/otc/rating.rb, line 80 def rated Account[self.rater_nick] end
rater()
click to toggle source
Returns the account of the user who created this rating.
@return [Account]
# File lib/bitcoin/otc/rating.rb, line 72 def rater Account[self.rater_nick] end
to_hash()
click to toggle source
Returns the hash representation of this rating.
@return [Hash]
# File lib/bitcoin/otc/rating.rb, line 113 def to_hash %w(id rater_nick rated_nick created_at rating notes).map(&:to_sym).inject({}) do |hash, attr| hash[attr] = self.instance_variable_get("@#{attr}") hash end end
to_i()
click to toggle source
Returns the integer representation of this rating.
@return [Integer]
# File lib/bitcoin/otc/rating.rb, line 88 def to_i self.rating end
to_json()
click to toggle source
Returns the JSON string representation of this rating.
@return [String]
# File lib/bitcoin/otc/rating.rb, line 96 def to_json hash = self.to_hash hash.each do |attr, value| case attr when :id, :rating hash[attr] = value.to_s when :created_at hash[attr] = value.strftime('%s') end end hash.to_json end