Class: ActivityLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/activity-logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir: nil, options: {}, config: nil) ⇒ ActivityLogger

Returns a new instance of ActivityLogger.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/activity-logger.rb', line 12

def initialize(dir: nil, options: {}, config: nil)
  
  @options = options
  @publish_html = false

  
  if config then
    
    h = SimpleConfig.new(config).to_h
    dir, @urlbase, @edit_url, @css_url, @xsl_path = \
                     %i(dir urlbase edit_url css_url xsl_path).map{|x| h[x]}
    @publish_html = true
  end
  
  Dir.chdir(dir) if dir
end

Instance Attribute Details

#xml_instruction=(value) ⇒ Object (writeonly)

Sets the attribute xml_instruction

Parameters:

  • value

    the value to set the attribute xml_instruction to.



10
11
12
# File 'lib/activity-logger.rb', line 10

def xml_instruction=(value)
  @xml_instruction = value
end

Instance Method Details

#create(desc = '', time = Time.now) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/activity-logger.rb', line 29

def create(desc='', time=Time.now)

  ddaily = DynarexDaily.new(nil, @options)
  
  ddaily.xml_instruction = @xml_instruction
  ddaily.create(time: time.to_s, desc: desc)
  ddaily.save

  if @publish_html then
    File.write 'index.txt', ddaily.to_s
    save_html() 
  end
  
end

#expired?Boolean

Returns true if the time from the last entry exceeds 45 minutes.

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
# File 'lib/activity-logger.rb', line 46

def expired?()
  records = DynarexDaily.new.to_h
  if records and !records.empty? then
    (Time.now - Time.parse(records.last[:time])) / 60 >= 45  
  else
    true
  end
end