Class: Gratitude::UserChart

Inherits:
Object
  • Object
show all
Extended by:
Connection
Defined in:
lib/gratitude/user_chart.rb

Constant Summary collapse

USER_CHARTS =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Connection

faraday

Constructor Details

#initialize(options = {}) ⇒ UserChart

Returns a new instance of UserChart.



11
12
13
14
15
16
17
# File 'lib/gratitude/user_chart.rb', line 11

def initialize(options = {})
  @username = options["username"]
  @date = Date.parse(options["date"]) if options["date"]
  @number_of_patrons = options["npatrons"]
  @receipts = options["receipts"]
  USER_CHARTS << self
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



8
9
10
# File 'lib/gratitude/user_chart.rb', line 8

def date
  @date
end

#number_of_patronsObject (readonly) Also known as: npatrons

Returns the value of attribute number_of_patrons.



8
9
10
# File 'lib/gratitude/user_chart.rb', line 8

def number_of_patrons
  @number_of_patrons
end

#receiptsObject (readonly)

Returns the value of attribute receipts.



8
9
10
# File 'lib/gratitude/user_chart.rb', line 8

def receipts
  @receipts
end

#usernameObject (readonly)

Returns the value of attribute username.



8
9
10
# File 'lib/gratitude/user_chart.rb', line 8

def username
  @username
end

Class Method Details

.all_for_user(username) ⇒ Object



19
20
21
22
23
# File 'lib/gratitude/user_chart.rb', line 19

def self.all_for_user(username)
  USER_CHARTS.clear if user_charts_contains_other_usernames?(username)
  collect_charts_for(username) if USER_CHARTS.empty?
  USER_CHARTS
end

.newest_for(username) ⇒ Object



25
26
27
# File 'lib/gratitude/user_chart.rb', line 25

def self.newest_for(username)
  sort_by_date_for_user(username).first
end

.oldest_for(username) ⇒ Object



29
30
31
# File 'lib/gratitude/user_chart.rb', line 29

def self.oldest_for(username)
  sort_by_date_for_user(username).last
end