Class: Afterburn::Project

Inherits:
Object
  • Object
show all
Includes:
Redis::Objects
Defined in:
lib/afterburn/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(board) ⇒ Project

Returns a new instance of Project.



27
28
29
# File 'lib/afterburn/project.rb', line 27

def initialize(board)
  @board = board
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



26
27
28
# File 'lib/afterburn/project.rb', line 26

def board
  @board
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/afterburn/project.rb', line 12

def id
  @id
end

Class Method Details

.by_member(member) ⇒ Object



18
19
20
# File 'lib/afterburn/project.rb', line 18

def self.by_member(member)
  member.boards.map { |board| Project.new(board) }
end

.by_member_name(member_name) ⇒ Object



14
15
16
# File 'lib/afterburn/project.rb', line 14

def self.by_member_name(member_name)
  Board.fetch_by_member(member_name).map { |board| Project.new(board) }
end

.find(id) ⇒ Object



22
23
24
# File 'lib/afterburn/project.rb', line 22

def self.find(id)
  new(Board.find(id))
end

Instance Method Details

#disable!Object



47
48
49
# File 'lib/afterburn/project.rb', line 47

def disable!
  enabled_value.value = nil
end

#enable!Object



43
44
45
# File 'lib/afterburn/project.rb', line 43

def enable!
  enabled_value.value = "1"
end

#enable=(enabled) ⇒ Object



51
52
53
# File 'lib/afterburn/project.rb', line 51

def enable=(enabled)
  enabled == "1" ? enable! : disable!
end

#enabled?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/afterburn/project.rb', line 55

def enabled?
  !!enabled_value.value
end

#interval_series_jsonObject



89
90
91
# File 'lib/afterburn/project.rb', line 89

def interval_series_json
  ListIntervalSeries.new(lists, interval_timestamps).to_json
end

#interval_timestampsObject



85
86
87
# File 'lib/afterburn/project.rb', line 85

def interval_timestamps
  intervals.map(&:timestamp)
end

#intervalsObject

TODO handle BoardIntervals not found



72
73
74
# File 'lib/afterburn/project.rb', line 72

def intervals
  @intervals ||= BoardInterval.find_all(interval_set.members)
end

#listsObject



59
60
61
# File 'lib/afterburn/project.rb', line 59

def lists
  @board.lists
end

#nameObject



39
40
41
# File 'lib/afterburn/project.rb', line 39

def name
  redis_name_value.value || @board.name
end

#name=(name) ⇒ Object



35
36
37
# File 'lib/afterburn/project.rb', line 35

def name=(name)
  redis_name_value.value = name
end

#record_intervalObject

TODO test



64
65
66
67
68
69
# File 'lib/afterburn/project.rb', line 64

def record_interval
  Time.now.tap do |timestamp|
    interval = BoardInterval.record(@board, timestamp)
    interval_set[interval.id] = timestamp.to_i
  end
end

#to_jsonObject



76
77
78
79
80
81
82
83
# File 'lib/afterburn/project.rb', line 76

def to_json
  {}.tap do |hash|
    hash['id'] = id
    hash['name'] = name
    hash['categories'] = interval_timestamps.map(&:to_date)
    hash['series'] = interval_series_json
  end
end

#update_attributes(attributes) ⇒ Object



93
94
95
96
97
# File 'lib/afterburn/project.rb', line 93

def update_attributes(attributes)
  attributes.each do |key, value|
    send("#{key}=", value)
  end
end