Class: SayTimeAction

Inherits:
DateTimeAction show all
Defined in:
lib/ruby-macrodroid/actions.rb

Overview

Category: Date/Time

Instance Attribute Summary

Attributes inherited from Action

#constraints

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods included from ObjectX

#action_to_object, #object_create, #varify

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(obj = nil) ⇒ SayTimeAction

Returns a new instance of SayTimeAction.



981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
# File 'lib/ruby-macrodroid/actions.rb', line 981

def initialize(obj=nil)
  
  h = if obj.is_a? Hash then
    obj
  elsif obj.is_a? Array
    
    e, macro = obj      
    {:'12_hour' => e.text('item/description').to_s[/^\d+/] == '12'}
    
  end 
  
  options = {
    :'12_hour' => true
  }

  super(options.merge h)

end

Instance Method Details

#invokeObject



1000
1001
1002
1003
1004
1005
# File 'lib/ruby-macrodroid/actions.rb', line 1000

def invoke()
  #time = ($env and $env[:time]) ? $env[:time] : Time.now
  time = Time.now
  tformat = @h['12_hour'] ? "%-I:%M%P" : "%H:%M"
  super(txt: time.strftime(tformat))
end

#to_pcObject



1007
1008
1009
# File 'lib/ruby-macrodroid/actions.rb', line 1007

def to_pc()
  'say current_time()'
end

#to_s(colour: false, indent: 0) ⇒ Object



1011
1012
1013
1014
1015
# File 'lib/ruby-macrodroid/actions.rb', line 1011

def to_s(colour: false, indent: 0)
  @s = 'Say Current Time'
  @s += "\n%s hour clock" % (@h[:'12_hour'] ? '12' : '24')
  super()
end