Class: Octospy::Parser
- Inherits:
-
Object
- Object
- Octospy::Parser
- Includes:
- Download, Gist, Issue, Organization, PullRequest, Release, Repository, User, Wiki
- Defined in:
- lib/octospy/parser.rb,
lib/octospy/parser/gist.rb,
lib/octospy/parser/user.rb,
lib/octospy/parser/wiki.rb,
lib/octospy/parser/issue.rb,
lib/octospy/parser/release.rb,
lib/octospy/parser/download.rb,
lib/octospy/parser/repository.rb,
lib/octospy/parser/organization.rb,
lib/octospy/parser/pull_request.rb
Defined Under Namespace
Modules: Download, Gist, Issue, Organization, PullRequest, Release, Repository, User, Wiki
Instance Method Summary collapse
- #behavior_color(string) ⇒ Object
- #build(hash) ⇒ Object
- #color_table ⇒ Object
- #colorize_to(string) ⇒ Object
- #default_params ⇒ Object
-
#initialize(event) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #parsing_method ⇒ Object
Methods included from Release
Methods included from Gist
Methods included from Download
Methods included from Wiki
Methods included from PullRequest
#parse_pull_request_event, #parse_pull_request_review_comment_event
Methods included from Issue
#parse_issue_comment_event, #parse_issues_event
Methods included from Repository
#parse_commit_comment_event, #parse_create_event, #parse_delete_event, #parse_fork_apply_event, #parse_fork_event, #parse_public_event, #parse_push_event
Methods included from Organization
#parse_member_event, #parse_team_add_event
Methods included from User
#parse_follow_event, #parse_watch_event
Constructor Details
#initialize(event) ⇒ Parser
Returns a new instance of Parser.
24 25 26 |
# File 'lib/octospy/parser.rb', line 24 def initialize(event) @event = event end |
Instance Method Details
#behavior_color(string) ⇒ Object
108 109 110 111 112 113 |
# 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) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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 = hash[:body][-3..-1] body = hash[:body][0...15] body << '-----8<----- c u t -----8<-----' body + 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 ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# 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) ⇒ Object
115 116 117 |
# 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 ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/octospy/parser.rb', line 28 def default_params { notice_body: false, nick: '', repository: '', status: '', link: '', title: '', body: [] } end |
#parse ⇒ Object
40 41 42 43 44 45 46 47 |
# 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 ⇒ Object
87 88 89 |
# File 'lib/octospy/parser.rb', line 87 def parsing_method "Parse#{@event.type}".underscore.to_sym end |