Class: Pivotal::Entry
- Inherits:
-
Object
- Object
- Pivotal::Entry
- Defined in:
- lib/pivotal/entry.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#end ⇒ Object
Returns the value of attribute end.
-
#start ⇒ Object
Returns the value of attribute start.
Class Method Summary collapse
- .dry_run(file) ⇒ Object
- .entries_from_hamster_tsv_export(file) ⇒ Object
- .from_hamster_tsv_line(line) ⇒ Object
- .upload_to_pivotal(file) ⇒ Object
Instance Method Summary collapse
- #invoice_time ⇒ Object
-
#pivotal_date ⇒ Object
Make pivotal happy with the specified date format.
-
#pivotal_time(fraction = 0.5) ⇒ Object
Round to increments of half hours.
- #post ⇒ Object
- #pretty_print ⇒ Object
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
34 35 36 |
# File 'lib/pivotal/entry.rb', line 34 def description @description end |
#end ⇒ Object
Returns the value of attribute end.
34 35 36 |
# File 'lib/pivotal/entry.rb', line 34 def end @end end |
#start ⇒ Object
Returns the value of attribute start.
34 35 36 |
# File 'lib/pivotal/entry.rb', line 34 def start @start end |
Class Method Details
.dry_run(file) ⇒ Object
11 12 13 |
# File 'lib/pivotal/entry.rb', line 11 def dry_run(file) entries_from_hamster_tsv_export(file).map(&:pretty_print) end |
.entries_from_hamster_tsv_export(file) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/pivotal/entry.rb', line 15 def entries_from_hamster_tsv_export(file) entries = [] File.read(file).lines.each do |line| next if line =~ /^activity/ entries << Entry.from_hamster_tsv_line(line) end entries end |
.from_hamster_tsv_line(line) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/pivotal/entry.rb', line 24 def from_hamster_tsv_line(line) parts = line.split("\t") entry = new entry.start = DateTime.parse(parts[1]) entry.end = DateTime.parse(parts[2]) entry.description = parts[5] entry end |
.upload_to_pivotal(file) ⇒ Object
7 8 9 |
# File 'lib/pivotal/entry.rb', line 7 def upload_to_pivotal(file) entries_from_hamster_tsv_export(file).map(&:post) end |
Instance Method Details
#invoice_time ⇒ Object
36 37 38 |
# File 'lib/pivotal/entry.rb', line 36 def invoice_time (((@end.to_time.to_i - @start.to_time.to_i) / 60) / 60.0).round(2) end |
#pivotal_date ⇒ Object
Make pivotal happy with the specified date format
49 50 51 |
# File 'lib/pivotal/entry.rb', line 49 def pivotal_date @start.strftime("%m/%d/%Y") end |
#pivotal_time(fraction = 0.5) ⇒ Object
Round to increments of half hours
41 42 43 44 45 46 |
# File 'lib/pivotal/entry.rb', line 41 def pivotal_time(fraction=0.5) multiplier = 1.0 / fraction val = (multiplier*invoice_time).round / multiplier val = 0.5 if val == 0 val end |
#post ⇒ Object
53 54 55 |
# File 'lib/pivotal/entry.rb', line 53 def post Connection.instance.post_form("shift[person_id]=#{Connection::PERSON_ID}&shift[project_id]=#{Connection::PROJECT_ID}&shift[date]=#{self.pivotal_date}&shift[hours]=#{self.pivotal_time}&shift[description]=#{self.description}&commit=Save", "/time_shifts") end |
#pretty_print ⇒ Object
57 58 59 |
# File 'lib/pivotal/entry.rb', line 57 def pretty_print puts "#{self.pivotal_date} ::: #{self.description} ::: #{self.pivotal_time}" end |