Class: TicketTag

Inherits:
Object
  • Object
show all
Defined in:
app/models/ticket_tag.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, color) ⇒ TicketTag

Returns a new instance of TicketTag.



3
4
5
6
# File 'app/models/ticket_tag.rb', line 3

def initialize(name, color)
  @name = name
  @color = color
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



8
9
10
# File 'app/models/ticket_tag.rb', line 8

def color
  @color
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'app/models/ticket_tag.rb', line 8

def name
  @name
end

Class Method Details

.from_s(string) ⇒ Object



10
11
12
13
14
15
# File 'app/models/ticket_tag.rb', line 10

def self.from_s(string)
  name, color = string.scan(/\[([^\]]+)\]\(([a-fA-F0-9]{6})\)/).flatten
  name = string unless name
  color = "e4e4e4" unless color
  new(name, color)
end

Instance Method Details

#to_hObject



21
22
23
# File 'app/models/ticket_tag.rb', line 21

def to_h
  {name: name, color: color}
end

#to_sObject



17
18
19
# File 'app/models/ticket_tag.rb', line 17

def to_s
  "[#{name}](#{color})"
end