Class: Discord::Embed

Inherits:
Object
  • Object
show all
Defined in:
lib/discord_notifier/embed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Embed

Returns a new instance of Embed.


5
6
7
8
# File 'lib/discord_notifier/embed.rb', line 5

def initialize(&block)
  @data = {}
  self.instance_exec(&block) if block_given?
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.


3
4
5
# File 'lib/discord_notifier/embed.rb', line 3

def data
  @data
end

Instance Method Details

#add_field(params) ⇒ Object Also known as: field

Raises:

  • (ArgumentError)

78
79
80
81
82
83
# File 'lib/discord_notifier/embed.rb', line 78

def add_field(params)
  raise ArgumentError, "Field Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:fields] ||= []
  @data[:fields] << params
end

#author(params) ⇒ Object

Raises:

  • (ArgumentError)

66
67
68
69
70
# File 'lib/discord_notifier/embed.rb', line 66

def author(params)
  raise ArgumentError, "Author Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:author] = params
end

#color(val) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/discord_notifier/embed.rb', line 30

def color(val)
  case val
  when String
    @data[:color] = val.delete('#').to_i(16)
  when Integer
    raise ArgumentError, 'Color must be 24 bit' if val >= 16_777_216
    @data[:color] = val
  else
    raise ArgumentError, 'Color must be hex or 24 bit int'
  end
end

#description(str) ⇒ Object

Raises:

  • (ArgumentError)

15
16
17
18
# File 'lib/discord_notifier/embed.rb', line 15

def description(str)
  raise ArgumentError, 'Description Embed data must be a String' unless str.is_a?(String)
  @data[:description] = str
end

Raises:

  • (ArgumentError)

72
73
74
75
76
# File 'lib/discord_notifier/embed.rb', line 72

def footer(params)
  raise ArgumentError, "Footer Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:footer] = params
end

#image(params) ⇒ Object

Raises:

  • (ArgumentError)

54
55
56
57
58
# File 'lib/discord_notifier/embed.rb', line 54

def image(params)
  raise ArgumentError, "Image Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:image] = params
end

#provider(params) ⇒ Object

Raises:

  • (ArgumentError)

60
61
62
63
64
# File 'lib/discord_notifier/embed.rb', line 60

def provider(params)
  raise ArgumentError, "Provider Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:provider] = params
end

#thumbnail(params) ⇒ Object

Raises:

  • (ArgumentError)

42
43
44
45
46
# File 'lib/discord_notifier/embed.rb', line 42

def thumbnail(params)
  raise ArgumentError, "Thumbnail Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:thumbnail] = params
end

#timestamp(date) ⇒ Object

Raises:

  • (ArgumentError)

25
26
27
28
# File 'lib/discord_notifier/embed.rb', line 25

def timestamp(date)
  raise ArgumentError, 'Timestamp Embed data must be a Date' unless date.is_a?(DateTime)
  @data[:timestamp] = date
end

#title(str) ⇒ Object

Raises:

  • (ArgumentError)

10
11
12
13
# File 'lib/discord_notifier/embed.rb', line 10

def title(str)
  raise ArgumentError, 'Title Embed data must be a String' unless str.is_a?(String)
  @data[:title] = str
end

#url(str) ⇒ Object

Raises:

  • (ArgumentError)

20
21
22
23
# File 'lib/discord_notifier/embed.rb', line 20

def url(str)
  raise ArgumentError, 'URL Embed data must be a String' unless str.is_a?(String)
  @data[:url] = str
end

#video(params) ⇒ Object

Raises:

  • (ArgumentError)

48
49
50
51
52
# File 'lib/discord_notifier/embed.rb', line 48

def video(params)
  raise ArgumentError, "Video Embed data must be a Hash" unless params.is_a?(Hash)

  @data[:video] = params
end