Class: Timestream::Hamster
- Inherits:
-
Object
- Object
- Timestream::Hamster
show all
- Defined in:
- lib/timestream/hamster.rb
Defined Under Namespace
Classes: Fact, Timestream
Instance Method Summary
collapse
Constructor Details
#initialize(start_time, end_time) ⇒ Hamster
Returns a new instance of Hamster.
48
49
50
51
|
# File 'lib/timestream/hamster.rb', line 48
def initialize(start_time, end_time)
@start_time = start_time
@end_time = end_time
end
|
Instance Method Details
#facts ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/timestream/hamster.rb', line 37
def facts
dbus_facts = proxy.GetFacts(@start_time.to_i, @end_time.to_i, '')
dbus_facts = dbus_facts[0]
dbus_facts.collect { |dbus_fact|
Fact.new(*dbus_fact)
}
end
|
#proxy ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/timestream/hamster.rb', line 53
def proxy
@proxy ||= begin
session_bus = DBus::SessionBus.instance
hamster_service = session_bus.service('org.gnome.Hamster')
hamster = hamster_service.object('/org/gnome/Hamster')
hamster.introspect
hamster.default_iface = 'org.gnome.Hamster'
hamster
end
end
|
#timestream_by_category ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/timestream/hamster.rb', line 85
def timestream_by_category
if @timestream_by_category.nil?
@timestream_by_category = Hash.new { |hash, category|
hash[category] = Timestream.new
}
facts.each do |fact|
timestream = @timestream_by_category[fact.category_name]
timestream[fact.date] += fact.delta_in_seconds.fdiv(60 * 60)
end
end
@timestream_by_category
end
|