class OpenSourceStats::Event

Constants

TYPES

Hash of event types to count as an event

The top-level key should be the event type The top-level value should be a hash used to filter acceptable key/value pairs

For the sub-hash, keys are keys to look for in the event, and the value is an array of acceptable values

Events that don’t match an event type and key/value pair with fail the in_scope? check

Attributes

actor[R]
id[R]
payload[R]
repo[R]
time[R]
type[R]

Public Class Methods

new(event) click to toggle source

Takes the raw event object from Octokit

# File lib/open_source_stats/event.rb, line 27
def initialize(event)
  @type = event[:type]
  @repo = event[:repo][:name]
  @actor = User.new(event[:actor][:login])
  @time = event[:created_at]
  @payload = event[:payload]
  @id = event[:id]
end

Public Instance Methods

==(other_event) click to toggle source

Use event IDs to compare uniquness via Array#uniq

# File lib/open_source_stats/event.rb, line 47
def ==(other_event)
  id == other_event.id
end
Also aliased as: eql?
commits() click to toggle source

How many commmits does this event involve?

For push events, this is the number of commits pushed For pull request events, this is the number of commits contained in the PR

# File lib/open_source_stats/event.rb, line 56
def commits
  case type
  when "PushEvent"
    payload[:commits].count
  when "PullRequestEvent"
    payload[:pull_request][:commits]
  else
    0
  end
end
eql?(other_event)
Alias for: ==
in_scope?() click to toggle source

Is this event type within our timeframe AND an acceptable event type?

# File lib/open_source_stats/event.rb, line 37
def in_scope?
  return false unless time >= OpenSourceStats.start_time
  return false unless TYPES.keys.include?(type)
  TYPES[type].each do |key, values|
    return false unless values.include? payload[key]
  end
  true
end