class Octospy::Parser
Public Class Methods
new(event)
click to toggle source
# File lib/octospy/parser.rb, line 24 def initialize(event) @event = event end
Public Instance Methods
behavior_color(string)
click to toggle source
# File lib/octospy/parser.rb, line 108 def behavior_color(string) color_table.each { |word, color| return color if string.include? "#{word}" } color_table[:default] end
build(hash)
click to toggle source
# File lib/octospy/parser.rb, line 49 def build(hash) header = "#{hash[:nick].to_s.colorize_for_irc.bold} #{colorize_to hash[:status]}" if hash[:repository] && !hash[:repository].empty? header = "(#{hash[:repository]}) #{header}" end if hash[:title] && !hash[:title].empty? header = "#{header} #{hash[:title]}" end if hash[:link] && !hash[:link].empty? header = "#{header} - #{hash[:link].shorten.to_s.colorize_for_irc.blue}" end body = if hash[:body].length > 20 body_footer = hash[:body][-3..-1] body = hash[:body][0...15] body << '-----8<----- c u t -----8<-----' body + body_footer else hash[:body] end [ { nick: hash[:nick], type: :notice, message: header }, { nick: hash[:nick], type: hash[:notice_body] ? :notice : :private, message: body } ] end
color_table()
click to toggle source
# File lib/octospy/parser.rb, line 91 def color_table { default: :aqua, created: :pink, commented: :yellow, pushed: :lime, forked: :seven_eleven, closed: :brown, deleted: :red, edited: :green, published: :blue, starred: :rainbow, followed: :seven_eleven, saved: :cyan } end
colorize_to(string)
click to toggle source
# File lib/octospy/parser.rb, line 115 def colorize_to(string) string.to_s.colorize_for_irc.send(behavior_color string).to_s end
default_params()
click to toggle source
# File lib/octospy/parser.rb, line 28 def default_params { notice_body: false, nick: '', repository: '', status: '', link: '', title: '', body: [] } end
parse()
click to toggle source
# File lib/octospy/parser.rb, line 40 def parse hash = default_params.merge( nick: @event.actor.login, repository: @event.repo.name ) hash.merge! self.send(parsing_method) build(hash) end
parsing_method()
click to toggle source
# File lib/octospy/parser.rb, line 87 def parsing_method "Parse#{@event.type}".underscore.to_sym end