Class: Badgeville::Activity

Inherits:
Object
  • Object
show all
Defined in:
lib/badgeville/activity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json = nil) ⇒ Activity

Returns a new instance of Activity.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/badgeville/activity.rb', line 8

def initialize(json=nil)
  if json
    @verb = json.delete("verb")
    @player_id = json.delete("player_id")
    @user_id = json.delete("user_id")
    @points = json.delete("points").to_i
    @created_at = DateTime.parse(json.delete("created_at")).to_time
    @rewards = json.delete("rewards").map do |award|
      Reward.new(award)
    end
    @meta = json.inject({}) do |meta, entry|
      k,v = entry
      meta[k.to_sym] = v
      meta
    end
  end
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



6
7
8
# File 'lib/badgeville/activity.rb', line 6

def created_at
  @created_at
end

#metaObject

Returns the value of attribute meta.



6
7
8
# File 'lib/badgeville/activity.rb', line 6

def meta
  @meta
end

#player_idObject

Returns the value of attribute player_id.



6
7
8
# File 'lib/badgeville/activity.rb', line 6

def player_id
  @player_id
end

#pointsObject

Returns the value of attribute points.



6
7
8
# File 'lib/badgeville/activity.rb', line 6

def points
  @points
end

#rewardsObject

Returns the value of attribute rewards.



6
7
8
# File 'lib/badgeville/activity.rb', line 6

def rewards
  @rewards
end

#user_idObject

Returns the value of attribute user_id.



6
7
8
# File 'lib/badgeville/activity.rb', line 6

def user_id
  @user_id
end

#verbObject

Returns the value of attribute verb.



6
7
8
# File 'lib/badgeville/activity.rb', line 6

def verb
  @verb
end