Class: Vkdonate::Donate

Inherits:
Object
  • Object
show all
Defined in:
lib/vkdonate/donate.rb

Overview

Single donation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, uid:, date:, sum:, msg:, anon:, visible:) ⇒ Donate

Save data about donation.

Parameters:

  • options (Hash)


39
40
41
42
43
44
45
46
47
# File 'lib/vkdonate/donate.rb', line 39

def initialize(id:, uid:, date:, sum:, msg:, anon:, visible:)
  @id = id
  @uid = uid
  @date = date
  @sum = sum
  @msg = msg
  @anon = anon
  @visible = visible
end

Instance Attribute Details

#anonBoolean (readonly) Also known as: anon?

Returns Whether donation is anonymous.

Returns:

  • (Boolean)

    Whether donation is anonymous



23
24
25
# File 'lib/vkdonate/donate.rb', line 23

def anon
  @anon
end

#dateDateTime (readonly)

Returns Date and time of donation.

Returns:

  • (DateTime)

    Date and time of donation



13
14
15
# File 'lib/vkdonate/donate.rb', line 13

def date
  @date
end

#idInteger (readonly)

Returns Unique payment ID.

Returns:

  • (Integer)

    Unique payment ID



7
8
9
# File 'lib/vkdonate/donate.rb', line 7

def id
  @id
end

#msgString (readonly) Also known as: message

Returns User message or nil if empty.

Returns:

  • (String)

    User message or nil if empty



19
20
21
# File 'lib/vkdonate/donate.rb', line 19

def msg
  @msg
end

#sumInteger (readonly)

Returns Size of donation.

Returns:

  • (Integer)

    Size of donation



16
17
18
# File 'lib/vkdonate/donate.rb', line 16

def sum
  @sum
end

#uidInteger (readonly)

Returns Donator VK ID.

Returns:

  • (Integer)

    Donator VK ID



10
11
12
# File 'lib/vkdonate/donate.rb', line 10

def uid
  @uid
end

#visibleBoolean (readonly) Also known as: visible?

Returns Whether donate is visible in group.

Returns:

  • (Boolean)

    Whether donate is visible in group



27
28
29
# File 'lib/vkdonate/donate.rb', line 27

def visible
  @visible
end

Class Method Details

.from_json(hash) ⇒ Donate

Parse from JSON hash.

Parameters:

  • hash (Hash)

    parsed JSON hash.

Returns:



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vkdonate/donate.rb', line 52

def self.from_json(hash)
  new(
    id: hash['id'],
    uid: hash['uid'],
    date: DateTime.parse(hash['date'] + " #{TIME_OFFSET}"),
    sum: hash['sum'],
    msg: hash['msg'].to_s,
    anon: Integer(hash['anon'].to_s, 10) != 0,
    visible: Integer(hash['visible'].to_s, 10) != 0
  )
end

Instance Method Details

#to_sString

Returns Human readable information.

Returns:

  • (String)

    Human readable information



65
66
67
# File 'lib/vkdonate/donate.rb', line 65

def to_s
  "Donation ##{id} by @#{uid} for #{sum}RUR (at #{date})"
end