Class: TimeTracker::Creator
- Inherits:
-
Object
- Object
- TimeTracker::Creator
- Defined in:
- lib/time_tracker.rb
Instance Method Summary collapse
- #index_to_month(i) ⇒ Object
-
#initialize ⇒ Creator
constructor
A new instance of Creator.
- #start_tracking ⇒ Object
Constructor Details
#initialize ⇒ Creator
Returns a new instance of Creator.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/time_tracker.rb', line 161 def initialize # configuration stuff begin config_file = File.read "config.json" rescue puts "Can't read configuration file" end @config = JSON.parse config_file # Open a file or pass a string to the parser client = HTTPClient.new cal_file = client.get_content @config["url"] # Parser returns an array of calendars because a single file # can have multiple calendars. cals = Icalendar.parse cal_file cal = cals.first # initialize months, yep 1 to 13 cause we can use month 1..12 # a little bit unclean but the use is more intuitive @months = Array.new 13.times do @months.push Month.new end # sort each event into the right month cal.events.each do |event| if event.start.year == @config["year"] then @months[event.start.month].add_event event end end end |
Instance Method Details
#index_to_month(i) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/time_tracker.rb', line 196 def index_to_month i result = "" case i when 1 result = "january" when 2 result = "february" when 3 result = "march" when 4 result = "april" when 5 result = "may" when 6 result = "june" when 7 result = "july" when 8 result = "august" when 9 result = "september" when 10 result = "october" when 11 result = "november" when 12 result = "december" else result = "error" end result end |
#start_tracking ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/time_tracker.rb', line 229 def start_tracking # sort events within the month and calculate +/- hours temp_offset = @config["offset"]; config = @config @months.each_with_index do |month, i| if i > 0 then month.sort_entries! month.global_offset = temp_offset # reading monthly working time with some dirty conversion for a more beautiful configuration file month.fixed_monthly_working_time = @config["working_time"][(index_to_month i)] month.calulate_working_time # monthly_working_time temp_offset = month.global_offset sheet = TimeSheet.new month, config sheet.print end end end |