Class: Gpuzzletime::Entry

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

Overview

Dataclass to wrap an entry

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.



13
14
15
16
# File 'lib/gpuzzletime/entry.rb', line 13

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/gpuzzletime/entry.rb', line 7

def 
  @account
end

#billableObject (readonly)

allow to read everything



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

def billable
  @billable
end

#dateObject

allow to read everything



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

def date
  @date
end

#descriptionObject

allow to read everything



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

def description
  @description
end

#finish_timeObject

allow to read everything



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

def finish_time
  @finish_time
end

#start_timeObject

allow to read everything



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

def start_time
  @start_time
end

#tagsObject

allow to read everything



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

def tags
  @tags
end

#ticketObject

allow to read everything



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

def ticket
  @ticket
end

Class Method Details

.from_timelog(matched_line) ⇒ Object



19
20
21
22
23
# File 'lib/gpuzzletime/entry.rb', line 19

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

Instance Method Details

#from_timelog(matched_line) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/gpuzzletime/entry.rb', line 26

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)


50
51
52
# File 'lib/gpuzzletime/entry.rb', line 50

def hidden?
  @description.match(/\*\*$/) # hide lunch and breaks
end

#infer_ptime_settingsObject



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

def infer_ptime_settings
  @account  = 
  @billable = infer_billable
end

#to_sObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gpuzzletime/entry.rb', line 59

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

#valid?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/gpuzzletime/entry.rb', line 46

def valid?
  @start_time && !hidden?
end