achoo 0.3 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/CHANGES +12 -0
  2. data/README.rdoc +26 -30
  3. data/Rakefile +3 -0
  4. data/bin/achoo +2 -2
  5. data/lib/achoo.rb +1 -139
  6. data/lib/achoo/achievo.rb +13 -0
  7. data/lib/achoo/achievo/form.rb +22 -0
  8. data/lib/achoo/achievo/hour_administration_form.rb +91 -0
  9. data/lib/achoo/achievo/hour_registration_form.rb +230 -0
  10. data/lib/achoo/achievo/hour_registration_form_ranged.rb +49 -0
  11. data/lib/achoo/achievo/lock_month_form.rb +44 -0
  12. data/lib/achoo/achievo/login_form.rb +27 -0
  13. data/lib/achoo/achievo/table.rb +30 -0
  14. data/lib/achoo/app.rb +153 -0
  15. data/lib/achoo/awake.rb +86 -100
  16. data/lib/achoo/extensions.rb +24 -0
  17. data/lib/achoo/ical.rb +47 -40
  18. data/lib/achoo/rc_loader.rb +42 -42
  19. data/lib/achoo/system.rb +8 -3
  20. data/lib/achoo/system/cstruct.rb +67 -0
  21. data/lib/achoo/system/log_entry.rb +24 -0
  22. data/lib/achoo/system/pm_suspend.rb +17 -20
  23. data/lib/achoo/system/utmp_record.rb +64 -0
  24. data/lib/achoo/system/wtmp.rb +14 -10
  25. data/lib/achoo/temporal.rb +8 -0
  26. data/lib/achoo/temporal/open_timespan.rb +16 -0
  27. data/lib/achoo/temporal/timespan.rb +122 -0
  28. data/lib/achoo/term.rb +58 -56
  29. data/lib/achoo/term/menu.rb +2 -2
  30. data/lib/achoo/term/table.rb +59 -60
  31. data/lib/achoo/ui.rb +13 -9
  32. data/lib/achoo/ui/commands.rb +60 -38
  33. data/lib/achoo/ui/common.rb +10 -7
  34. data/lib/achoo/ui/date_chooser.rb +69 -65
  35. data/lib/achoo/ui/date_choosers.rb +15 -14
  36. data/lib/achoo/ui/exception_handling.rb +14 -12
  37. data/lib/achoo/ui/month_chooser.rb +37 -24
  38. data/lib/achoo/ui/optionally_ranged_date_chooser.rb +29 -25
  39. data/lib/achoo/ui/register_hours.rb +116 -114
  40. data/lib/achoo/vcs.rb +32 -30
  41. data/lib/achoo/vcs/git.rb +18 -14
  42. data/lib/achoo/vcs/subversion.rb +25 -23
  43. metadata +30 -24
  44. data/lib/achoo/binary.rb +0 -7
  45. data/lib/achoo/binary/cstruct.rb +0 -60
  46. data/lib/achoo/binary/utmp_record.rb +0 -59
  47. data/lib/achoo/form.rb +0 -18
  48. data/lib/achoo/hour_administration_form.rb +0 -131
  49. data/lib/achoo/hour_registration_form.rb +0 -227
  50. data/lib/achoo/hour_registration_form_ranged.rb +0 -45
  51. data/lib/achoo/lock_month_form.rb +0 -40
  52. data/lib/achoo/open_timespan.rb +0 -13
  53. data/lib/achoo/timespan.rb +0 -119
@@ -1,45 +0,0 @@
1
- require 'achoo/hour_registration_form'
2
-
3
- class Achoo::HourRegistrationFormRanged < Achoo::HourRegistrationForm
4
-
5
- def initialize(agent)
6
- super
7
-
8
- @page = @agent.get(atk_submit_to_url(@page.link_with(:text => 'Select range').href))
9
- @form = @page.form('entryform')
10
- end
11
-
12
- def date=(date_range)
13
- super(date_range[0])
14
-
15
- to_day_field.value = date_range[1].strftime('%d')
16
- to_month_field.value = date_range[1].strftime('%m')
17
- to_year_field.value = date_range[1].year
18
- end
19
-
20
- def date
21
- start = super
22
- finish = Date.new(to_year_field.value.to_i, to_month_field.value.to_i,
23
- to_day_field.value.to_i)
24
- [start, finish]
25
- end
26
-
27
- private
28
-
29
- def to_day_field
30
- @form.field_with(:name => 'todate[day]')
31
- end
32
-
33
- def to_month_field
34
- @form.field_with(:name => 'todate[month]')
35
- end
36
-
37
- def to_year_field
38
- @form.field_with(:name => 'todate[year]')
39
- end
40
-
41
- def date_to_s
42
- date.map {|d| d.strftime("%Y-%m-%d")}.join(" -> ")
43
- end
44
-
45
- end
@@ -1,40 +0,0 @@
1
- class Achoo; end
2
-
3
- class Achoo::LockMonthForm
4
-
5
- def initialize(agent)
6
- @agent = agent
7
- end
8
-
9
- def lock_month(period)
10
- page = @agent.get(RC[:lock_months_url])
11
- @form = page.form('entryform')
12
-
13
- @form.period = period
14
- unless user_select.nil?
15
- user_select.options.each do |opt|
16
- if opt.text.match(/\(#{RC[:user]}\)$/)
17
- opt.select
18
- end
19
- end
20
- end
21
-
22
- end
23
-
24
- def print_values
25
- puts "Month: #{@form.period}"
26
- puts " User: #{user_select.value}" unless user_select.nil?
27
-
28
- end
29
-
30
- def submit
31
- @form.submit
32
- end
33
-
34
- private
35
-
36
- def user_select
37
- @form.field_with(:name => 'userid')
38
- end
39
-
40
- end
@@ -1,13 +0,0 @@
1
- require 'achoo/timespan'
2
-
3
- class Achoo; end
4
-
5
- class Achoo::OpenTimespan < Achoo::Timespan
6
-
7
- def to_s
8
- s = super
9
- s.sub!(/^\([^)]+\)/, '(?+??:??)')
10
- s.sub!(/- .*$/, '- ?')
11
- s
12
- end
13
- end
@@ -1,119 +0,0 @@
1
- require 'time'
2
-
3
- class Achoo; end
4
-
5
- class Achoo::Timespan
6
-
7
- SECONDS_IN_A_DAY = 86400
8
- SECONDS_IN_AN_HOUR = 3600
9
- SECONDS_IN_A_MINUTE = 60
10
-
11
- attr :start
12
- attr :end
13
-
14
- def initialize(start, end_)
15
- raise ArgumentError.new('Nil in parameters not allowed') if start.nil? || end_.nil?
16
-
17
- self.start = start
18
- self.end = end_
19
- end
20
-
21
- def start=(timeish)
22
- @start = to_time(timeish)
23
- end
24
-
25
- def end=(timeish)
26
- @end = to_time(timeish)
27
- end
28
-
29
- def to_s
30
- duration = duration_string
31
- from_to = from_to_string
32
-
33
- sprintf("(%s) %s", duration, from_to)
34
- end
35
-
36
- def contains?(timeish_or_timespan)
37
- if timeish_or_timespan.is_a? Achoo::Timespan
38
- timespan = timeish_or_timespan
39
- return start <= timespan.start && self.end >= timespan.end
40
- else
41
- time = to_time(timeish_or_timespan)
42
- return start <= time && self.end >= time
43
- end
44
- end
45
-
46
- def overlaps?(timespan)
47
- start <= timespan.start && self.end >= timespan.start \
48
- || start <= timespan.end && self.end >= timespan.end \
49
- || contains?(timespan) || timespan.contains?(self)
50
- end
51
-
52
- private
53
-
54
- def to_time(timeish)
55
- case timeish
56
- when Time
57
- timeish.clone
58
- when DateTime
59
- Time.local(timeish.year, timeish.month, timeish.day, timeish.hour,timeish.minute, timeish.second)
60
- when Date
61
- Time.local(timeish.year, timeish.month, timeish.day)
62
- else
63
- if timeish.respond_to?(:to_s)
64
- Time.parse(timeish.to_s)
65
- else
66
- raise ArgumentError.new("Don't know how to convert #{timeish.class} to Time")
67
- end
68
- end
69
- end
70
-
71
-
72
- def duration_string
73
- delta = @end - @start
74
- d = delta.to_i / SECONDS_IN_A_DAY
75
-
76
- delta = delta - d*SECONDS_IN_A_DAY
77
- h = delta.to_i / SECONDS_IN_AN_HOUR
78
-
79
- delta = delta - h*SECONDS_IN_AN_HOUR
80
- m = delta.to_i / SECONDS_IN_A_MINUTE
81
-
82
- sprintf "%d+%02d:%02d", d, h, m
83
- end
84
-
85
- def from_to_string
86
- today = Date.today
87
- start_date = start.send(:to_date)
88
- end_date = self.end.send(:to_date)
89
-
90
- format = if start_date == today
91
- "Today"
92
- elsif start_date.month == today.month &&
93
- start_date.year == today.year
94
- "%a %e."
95
- elsif start_date.year == today.year
96
- "%a %e. %b"
97
- else
98
- "%a %e. %b %Y"
99
- end
100
- from = start.strftime(format << " %R")
101
-
102
- format = if end_date == start_date
103
- "%R"
104
- elsif end_date == today
105
- "Today %R"
106
- elsif end_date.month == today.month &&
107
- end_date.year == today.year
108
- "%a %e. %R"
109
- elsif end_date.year == today.year
110
- "%a %e. %b %R"
111
- else
112
- "%a %e. %b %Y %R"
113
- end
114
- to = self.end.strftime(format)
115
-
116
- sprintf "%s - %s", from, to
117
- end
118
-
119
- end