Class: GHArchive::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/gh-archive/events.rb,
lib/gh-archive/events.rb

Constant Summary collapse

IMPLEMENTATIONS =
ObjectSpace.each_object(Class).select { |klass| klass < self }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Event

Returns a new instance of Event.



14
15
16
17
# File 'lib/gh-archive/events.rb', line 14

def initialize(json)
    @json = json.freeze
    @payload = json['payload']
end

Class Method Details

.parse(json) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/gh-archive/events.rb', line 6

def self.parse(json)
    IMPLEMENTATIONS.each do |event_class|
        return event_class.new(json) if event_class.fits?(json)
    end
    
    return Event.new(json)
end

Instance Method Details

#actorObject



28
29
30
# File 'lib/gh-archive/events.rb', line 28

def actor
    User.new(@json['actor'])
end

#created_atObject Also known as: time



23
24
25
# File 'lib/gh-archive/events.rb', line 23

def created_at
    Time.parse(@json['created_at'])
end

#jsonObject



40
41
42
# File 'lib/gh-archive/events.rb', line 40

def json
    @json
end

#public?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/gh-archive/events.rb', line 19

def public?
    @json['public']
end

#repoObject



32
33
34
35
36
37
38
# File 'lib/gh-archive/events.rb', line 32

def repo
    Repository.new(
        @json['repo']['id'],
        @json['repo']['name'],
        @json['repo']['url']
    )
end