Class: Ptimelog::Entry

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

Overview

Dataclass to wrap an entry

Constant Summary collapse

BILLABLE =
1
NON_BILLABLE =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Configuration.instance) ⇒ Entry

Returns a new instance of Entry.



16
17
18
19
# File 'lib/ptimelog/entry.rb', line 16

def initialize(config = Configuration.instance)
  @config = config
  @script = Script.new(@config[:dir])
end

Instance Attribute Details

#accountObject (readonly)

allow to read everything



7
8
9
# File 'lib/ptimelog/entry.rb', line 7

def 
  @account
end

#billableObject (readonly)

allow to read everything



7
8
9
# File 'lib/ptimelog/entry.rb', line 7

def billable
  @billable
end

#dateObject

allow to read everything



7
8
9
# File 'lib/ptimelog/entry.rb', line 7

def date
  @date
end

#descriptionObject

allow to read everything



7
8
9
# File 'lib/ptimelog/entry.rb', line 7

def description
  @description
end

#finish_timeObject

allow to read everything



7
8
9
# File 'lib/ptimelog/entry.rb', line 7

def finish_time
  @finish_time
end

#start_timeObject

allow to read everything



7
8
9
# File 'lib/ptimelog/entry.rb', line 7

def start_time
  @start_time
end

#tagsObject

allow to read everything



7
8
9
# File 'lib/ptimelog/entry.rb', line 7

def tags
  @tags
end

#ticketObject

allow to read everything



7
8
9
# File 'lib/ptimelog/entry.rb', line 7

def ticket
  @ticket
end

Class Method Details

.from_timelog(matched_line) ⇒ Object



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

def from_timelog(matched_line)
  entry = new
  entry.from_timelog(matched_line)
  entry
end

Instance Method Details

#billable?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/ptimelog/entry.rb', line 62

def billable?
  @billable == BILLABLE
end

#from_timelog(matched_line) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/ptimelog/entry.rb', line 29

def from_timelog(matched_line)
  self.date        = matched_line[:date]
  self.ticket      = matched_line[:ticket]
  self.description = matched_line[:description]
  self.finish_time = matched_line[:time]
  self.tags        = matched_line[:tags]

  infer_ptime_settings
end

#hidden?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/ptimelog/entry.rb', line 58

def hidden?
  @description.to_s.end_with?('**') # hide lunch and breaks
end

#infer_ptime_settingsObject

this method will be reduced in 0.7, when support for parsers is removed



67
68
69
70
71
72
73
74
75
76
# File 'lib/ptimelog/entry.rb', line 67

def infer_ptime_settings
  return if hidden?

  if @script.inferer(script_name).exist?
    @account, @billable = 
  else
    @account  = 
    @billable = infer_billable
  end
end

#to_sObject



78
79
80
81
82
83
# File 'lib/ptimelog/entry.rb', line 78

def to_s
  [
    @start_time, '-', @finish_time,
    [@ticket, @description, @tags, @account].compact.join(' : '),
  ].compact.join(' ')
end

#valid?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/ptimelog/entry.rb', line 54

def valid?
  @start_time && !hidden?
end