Class: Ptimelog::Entry
- Inherits:
-
Object
- Object
- Ptimelog::Entry
- Defined in:
- lib/ptimelog/entry.rb
Overview
Dataclass to wrap an entry
Constant Summary collapse
- BILLABLE =
1- NON_BILLABLE =
0
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
allow to read everything else.
-
#billable ⇒ Object
readonly
allow to read everything else.
-
#date ⇒ Object
define only trivial writers, omit special and derived values.
-
#description ⇒ Object
define only trivial writers, omit special and derived values.
-
#finish_time ⇒ Object
allow to read everything else.
-
#start_time ⇒ Object
allow to read everything else.
-
#tags ⇒ Object
allow to read everything else.
-
#ticket ⇒ Object
define only trivial writers, omit special and derived values.
Class Method Summary collapse
Instance Method Summary collapse
- #billable? ⇒ Boolean
- #duration ⇒ Object
- #from_timelog(matched_line) ⇒ Object
- #hidden? ⇒ Boolean
- #infer_ptime_settings ⇒ Object
-
#initialize(config = Configuration.instance) ⇒ Entry
constructor
A new instance of Entry.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(config = Configuration.instance) ⇒ Entry
Returns a new instance of Entry.
17 18 19 20 |
# File 'lib/ptimelog/entry.rb', line 17 def initialize(config = Configuration.instance) @config = config @script = Script.new(@config[:dir]) end |
Instance Attribute Details
#account ⇒ Object (readonly)
allow to read everything else
12 13 14 |
# File 'lib/ptimelog/entry.rb', line 12 def account @account end |
#billable ⇒ Object (readonly)
allow to read everything else
12 13 14 |
# File 'lib/ptimelog/entry.rb', line 12 def billable @billable end |
#date ⇒ Object
define only trivial writers, omit special and derived values
9 10 11 |
# File 'lib/ptimelog/entry.rb', line 9 def date @date end |
#description ⇒ Object
define only trivial writers, omit special and derived values
9 10 11 |
# File 'lib/ptimelog/entry.rb', line 9 def description @description end |
#finish_time ⇒ Object
allow to read everything else
12 13 14 |
# File 'lib/ptimelog/entry.rb', line 12 def finish_time @finish_time end |
#start_time ⇒ Object
allow to read everything else
12 13 14 |
# File 'lib/ptimelog/entry.rb', line 12 def start_time @start_time end |
#tags ⇒ Object
allow to read everything else
12 13 14 |
# File 'lib/ptimelog/entry.rb', line 12 def end |
#ticket ⇒ Object
define only trivial writers, omit special and derived values
9 10 11 |
# File 'lib/ptimelog/entry.rb', line 9 def ticket @ticket end |
Class Method Details
.from_timelog(matched_line) ⇒ Object
23 24 25 26 27 |
# File 'lib/ptimelog/entry.rb', line 23 def from_timelog(matched_line) entry = new entry.from_timelog(matched_line) entry end |
Instance Method Details
#billable? ⇒ Boolean
63 64 65 |
# File 'lib/ptimelog/entry.rb', line 63 def billable? @billable == BILLABLE end |
#duration ⇒ Object
74 75 76 |
# File 'lib/ptimelog/entry.rb', line 74 def duration (Time.parse(@finish_time) - Time.parse(@start_time)).to_i end |
#from_timelog(matched_line) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/ptimelog/entry.rb', line 30 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. = matched_line[:tags] infer_ptime_settings end |
#hidden? ⇒ Boolean
59 60 61 |
# File 'lib/ptimelog/entry.rb', line 59 def hidden? @description.to_s.end_with?('**') # hide lunch and breaks end |
#infer_ptime_settings ⇒ Object
67 68 69 70 71 72 |
# File 'lib/ptimelog/entry.rb', line 67 def infer_ptime_settings return if hidden? return unless @script.inferer(script_name).exist? @account, @billable = infer_account_and_billable end |
#to_s ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ptimelog/entry.rb', line 78 def to_s billable = billable? ? '($)' : nil tag_list = Array().compact = tag_list.join(' ') if tag_list.any? desc = [@ticket, @description].compact.join(': ') acc = [@account, billable].compact.join(' ') if @account [ @start_time, '-', @finish_time, '∴', [desc, , acc].compact.join(' ∴ '), ].compact.join(' ') end |
#valid? ⇒ Boolean
55 56 57 |
# File 'lib/ptimelog/entry.rb', line 55 def valid? @start_time && duration.positive? && !hidden? end |