Class: IdobataHook::Source
- Inherits:
-
Object
- Object
- IdobataHook::Source
- Defined in:
- lib/idobata_hook/source.rb
Class Method Summary collapse
Instance Method Summary collapse
- #force_html? ⇒ Boolean
-
#initialize(*messages) ⇒ Source
constructor
A new instance of Source.
- #parse(messages) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*messages) ⇒ Source
Returns a new instance of Source.
3 4 5 |
# File 'lib/idobata_hook/source.rb', line 3 def initialize(*) @text, @force_html = parse(.flatten) end |
Class Method Details
.htmlize(message) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/idobata_hook/source.rb', line 26 def htmlize() return if .is_a? String type, text = .first case type.to_s when 'label' %(<span class="label">#{text}</span>) when /label-(.+)/ %(<span class="label label-#{$1}">#{text}</span>) when 'badge' %(<span class="badge">#{text}</span>) when /badge-(.+)/ %(<span class="badge badge-#{$1}">#{text}</span>) when 'emoji' %(<img class="emoji" alt=":#{text}:" src="/images/emoji/#{text}.png">) when 'fa' %(<i class="fa fa-#{text}"></i>) when 'commit-id' %(<span class="commit-id">#{text}</span>) else raise "unsupported type: #{type}" end end |
Instance Method Details
#force_html? ⇒ Boolean
7 8 9 |
# File 'lib/idobata_hook/source.rb', line 7 def force_html? @force_html end |
#parse(messages) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/idobata_hook/source.rb', line 15 def parse() force_html = false text = .map do || next if .is_a? String force_html ||= true Source.htmlize() end.join [text, force_html] end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/idobata_hook/source.rb', line 11 def to_s @text end |