Class: Redpomo::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/redpomo/entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, datetime, duration) ⇒ Entry

Returns a new instance of Entry.



22
23
24
25
26
# File 'lib/redpomo/entry.rb', line 22

def initialize(text, datetime, duration)
  @text = text
  @datetime = datetime
  @duration = duration
end

Instance Attribute Details

#datetimeObject (readonly)

Returns the value of attribute datetime.



20
21
22
# File 'lib/redpomo/entry.rb', line 20

def datetime
  @datetime
end

#durationObject (readonly)

Returns the value of attribute duration.



20
21
22
# File 'lib/redpomo/entry.rb', line 20

def duration
  @duration
end

#textObject (readonly)

Returns the value of attribute text.



20
21
22
# File 'lib/redpomo/entry.rb', line 20

def text
  @text
end

Class Method Details

.csv_rows(text) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/redpomo/entry.rb', line 12

def self.csv_rows(text)
  if text.match /^Export data created/
    CSV.parse text.split("\n")[4..-1].join("\n")
  else
    CSV.parse text
  end
end

.load_from_csv(text) ⇒ Object



6
7
8
9
10
# File 'lib/redpomo/entry.rb', line 6

def self.load_from_csv(text)
  csv_rows(text).map do |data|
    Entry.new(data[0], DateTime.parse(data[1]), data[2].to_i * 60.0) if data.size >= 3
  end.compact.sort_by { |entry| entry.datetime }
end

Instance Method Details

#dateObject



28
29
30
# File 'lib/redpomo/entry.rb', line 28

def date
  datetime.to_date
end

#end_timeObject



36
37
38
# File 'lib/redpomo/entry.rb', line 36

def end_time
  time + duration
end

#push!Object



52
53
54
# File 'lib/redpomo/entry.rb', line 52

def push!
  tracker.push_entry!(self) if pushable?
end

#pushable?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/redpomo/entry.rb', line 56

def pushable?
  tracker.present? && tracker.pushable_entry?(self)
end

#same_date?(entry) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/redpomo/entry.rb', line 40

def same_date?(entry)
  date == entry.date
end

#same_text?(entry) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/redpomo/entry.rb', line 44

def same_text?(entry)
  text == entry.text
end

#timeObject



32
33
34
# File 'lib/redpomo/entry.rb', line 32

def time
  datetime.to_time
end

#to_taskObject



48
49
50
# File 'lib/redpomo/entry.rb', line 48

def to_task
  Task.new(nil, text)
end

#trackerObject



60
61
62
# File 'lib/redpomo/entry.rb', line 60

def tracker
  to_task.tracker
end