Class: Rubord::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rubord/structs/parser.rb

Constant Summary collapse

CHANNEL_MENTION_REGEX =
/<#(\d{17,22})>/.freeze

Instance Method Summary collapse

Instance Method Details

#channel_mentions(text) ⇒ Object



49
50
51
52
53
# File 'lib/rubord/structs/parser.rb', line 49

def channel_mentions(text)
  return [] unless text

  text.scan(CHANNEL_MENTION_REGEX).flatten.map(&:to_i)
end

#color(value) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rubord/structs/parser.rb', line 32

def color(value)
  return nil if value.nil?

  case value
  when Symbol
    hex_to_int(COLORS[value])
  when String
    if COLORS.key?(value.to_sym)
      hex_to_int(COLORS[value.to_sym])
    else
      hex_to_int(value)
    end
  else
    value.to_i
  end
end

#timestamp(value) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/rubord/structs/parser.rb', line 23

def timestamp(value)
  return value if value.is_a?(Time)
  return nil unless value

  Time.parse(value.to_s)
rescue ArgumentError
  nil
end