ruby-macrodroid 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/ruby-macrodroid.rb +108 -30
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2f43b1d737df8ffc21bb31f9a7df56964963ba3b88a6e51e008c45ca0d4e5f6
|
4
|
+
data.tar.gz: 6e587a62b683867b37f28dfba70728971e19647cfa803a804ea123c1eb0955b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b247e2d22eac6c837d9bcacf38697b63ab80a41c2affca2adb7389b39423813c9d1816f9c9dd697a013ad75b5417ca2143ca4e040be819a09a67a939765aae2f
|
7
|
+
data.tar.gz: 1a91db74afbbfbe1622d3e19241c9a99ddd05c0ef975e7ac037102104497d12a191c305a4ceb9ab0f5d7d7d476060398b4648ea927bc3135ab52b5633f562e0f
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/ruby-macrodroid.rb
CHANGED
@@ -110,8 +110,8 @@
|
|
110
110
|
require 'yaml'
|
111
111
|
require 'rowx'
|
112
112
|
require 'uuid'
|
113
|
-
require 'glw'
|
114
|
-
require 'geozone'
|
113
|
+
#require 'glw'
|
114
|
+
#require 'geozone'
|
115
115
|
require 'rxfhelper'
|
116
116
|
require 'chronic_cron'
|
117
117
|
|
@@ -361,9 +361,9 @@ class Macro
|
|
361
361
|
attr_reader :local_variables, :triggers, :actions, :constraints, :guid
|
362
362
|
attr_accessor :title, :description
|
363
363
|
|
364
|
-
def initialize(name=nil,
|
364
|
+
def initialize(name=nil, geofences: geofences, debug: false)
|
365
365
|
|
366
|
-
@title, @
|
366
|
+
@title, @geofences, @debug = name, geofences, debug
|
367
367
|
|
368
368
|
puts 'inside Macro#initialize' if @debug
|
369
369
|
|
@@ -518,7 +518,11 @@ class Macro
|
|
518
518
|
puts 'found trigger ' + r.inspect if @debug
|
519
519
|
|
520
520
|
if r then
|
521
|
-
r[0]
|
521
|
+
if r[0] == GeofenceTrigger then
|
522
|
+
GeofenceTrigger.new(r[1], geofences: @geofences)
|
523
|
+
else
|
524
|
+
r[0].new(r[1])
|
525
|
+
end
|
522
526
|
end
|
523
527
|
|
524
528
|
end
|
@@ -662,7 +666,7 @@ EOF
|
|
662
666
|
|
663
667
|
if klass == GeofenceTrigger then
|
664
668
|
puts 'GeofenceTrigger found'.highlight if $debug
|
665
|
-
|
669
|
+
GeofenceTrigger.new(h, geofences: @geofences)
|
666
670
|
else
|
667
671
|
klass.new h
|
668
672
|
end
|
@@ -679,12 +683,14 @@ class MacroDroid
|
|
679
683
|
using ColouredText
|
680
684
|
using Params
|
681
685
|
|
682
|
-
attr_reader :macros, :
|
686
|
+
attr_reader :macros, :geofences
|
683
687
|
|
684
688
|
def initialize(obj=nil, debug: false)
|
685
689
|
|
686
690
|
@debug = debug
|
687
691
|
|
692
|
+
@geofences = {}
|
693
|
+
|
688
694
|
if obj then
|
689
695
|
|
690
696
|
raw_s, _ = RXFHelper.read(obj)
|
@@ -708,10 +714,25 @@ class MacroDroid
|
|
708
714
|
|
709
715
|
puts 'before RowX.new' if @debug
|
710
716
|
|
711
|
-
s2 = s.gsub(/^
|
712
|
-
.gsub(/^
|
713
|
-
|
717
|
+
s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
|
718
|
+
.gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\
|
719
|
+
.gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
|
720
|
+
|
721
|
+
raw_macros, raw_geofences = s2.split(/(?=^macro:)/,2).reverse
|
722
|
+
|
723
|
+
if raw_geofences then
|
724
|
+
|
725
|
+
geoxml = RowX.new(raw_geofences).to_xml
|
726
|
+
|
727
|
+
geodoc = Rexle.new(geoxml)
|
728
|
+
geofences = geodoc.root.xpath('item/geofence')
|
729
|
+
@geofences = fetch_geofences(geofences) if geofences.any?
|
730
|
+
|
731
|
+
end
|
732
|
+
|
733
|
+
xml = RowX.new(raw_macros).to_xml
|
714
734
|
import_rowxml(xml)
|
735
|
+
|
715
736
|
elsif s =~ /^# /
|
716
737
|
xml = pc_to_xml(s)
|
717
738
|
import_xml(xml)
|
@@ -721,8 +742,6 @@ class MacroDroid
|
|
721
742
|
|
722
743
|
@h = build_h
|
723
744
|
|
724
|
-
|
725
|
-
|
726
745
|
end
|
727
746
|
|
728
747
|
else
|
@@ -777,7 +796,13 @@ class MacroDroid
|
|
777
796
|
|
778
797
|
def to_h()
|
779
798
|
|
780
|
-
|
799
|
+
h = {
|
800
|
+
geofence_data: {
|
801
|
+
geofence_map: @geofences.map {|key, value| [key, value.to_h] }.to_h
|
802
|
+
},
|
803
|
+
macro_list: @macros.map(&:to_h)
|
804
|
+
}
|
805
|
+
@h.merge(h).to_camel_case
|
781
806
|
|
782
807
|
end
|
783
808
|
|
@@ -797,6 +822,32 @@ class MacroDroid
|
|
797
822
|
|
798
823
|
private
|
799
824
|
|
825
|
+
def fetch_geofences(nodes)
|
826
|
+
|
827
|
+
nodes.map do |e|
|
828
|
+
|
829
|
+
name = e.text.to_s.strip
|
830
|
+
item = e.element('item')
|
831
|
+
coordinates = item.text('coordinates')
|
832
|
+
latitude, longitude = coordinates.split(/, */,2)
|
833
|
+
radius = item.text('radius')
|
834
|
+
|
835
|
+
id = UUID.new.generate
|
836
|
+
|
837
|
+
h = {
|
838
|
+
name: name,
|
839
|
+
longitude: longitude,
|
840
|
+
latitude: latitude,
|
841
|
+
radius: radius,
|
842
|
+
id: id
|
843
|
+
}
|
844
|
+
|
845
|
+
[id.to_sym, GeofenceMap.new(h)]
|
846
|
+
|
847
|
+
end.to_h
|
848
|
+
|
849
|
+
end
|
850
|
+
|
800
851
|
def import_json(s)
|
801
852
|
|
802
853
|
h = JSON.parse(s, symbolize_names: true)
|
@@ -809,7 +860,7 @@ class MacroDroid
|
|
809
860
|
# fetch the geofence data
|
810
861
|
if @h[:geofence_data] then
|
811
862
|
|
812
|
-
@
|
863
|
+
@geofences = @h[:geofence_data][:geofence_map].map do |id, properties|
|
813
864
|
[id, GeofenceMap.new(properties)]
|
814
865
|
end.to_h
|
815
866
|
|
@@ -818,9 +869,9 @@ class MacroDroid
|
|
818
869
|
@macros = @h[:macro_list].map do |macro|
|
819
870
|
|
820
871
|
puts ('macro: ' + macro.inspect).debug if @debug
|
821
|
-
|
872
|
+
# puts '@geofences: ' + @geofences.inspect if @debug
|
822
873
|
|
823
|
-
m = Macro.new(
|
874
|
+
m = Macro.new(geofences: @geofences.map(&:last), debug: @debug )
|
824
875
|
m.import_h(macro)
|
825
876
|
m
|
826
877
|
|
@@ -833,13 +884,15 @@ class MacroDroid
|
|
833
884
|
def import_rowxml(raws)
|
834
885
|
|
835
886
|
s = RXFHelper.read(raws).first
|
836
|
-
puts 's: ' + s.inspect if
|
887
|
+
puts 's: ' + s.inspect if @debug
|
837
888
|
doc = Rexle.new(s)
|
838
|
-
puts 'after doc' if
|
889
|
+
puts 'after doc' if @debug
|
890
|
+
puts 'import_rowxml: @geofences: ' + @geofences.inspect if @debug
|
891
|
+
geofences = @geofences
|
839
892
|
|
840
893
|
@macros = doc.root.xpath('item').map do |node|
|
841
|
-
|
842
|
-
Macro.new.import_xml(node)
|
894
|
+
puts ('geofences: ' + geofences.inspect).highlight if @debug
|
895
|
+
Macro.new(geofences: geofences.map(&:last), debug: @debug).import_xml(node)
|
843
896
|
|
844
897
|
end
|
845
898
|
|
@@ -862,7 +915,7 @@ class MacroDroid
|
|
862
915
|
|
863
916
|
@macros = doc.root.xpath('macro').map do |node|
|
864
917
|
|
865
|
-
Macro.new.import_xml(node)
|
918
|
+
Macro.new(geofences: @geofences.map(&:last), debug: @debug).import_xml(node)
|
866
919
|
|
867
920
|
end
|
868
921
|
end
|
@@ -895,8 +948,23 @@ class GeofenceMap
|
|
895
948
|
|
896
949
|
attr_accessor :name, :longitude, :latitude, :radius, :id
|
897
950
|
|
898
|
-
def initialize(
|
899
|
-
|
951
|
+
def initialize(id: '', longitude: '', latitude: '', name: '', radius: '')
|
952
|
+
|
953
|
+
@id, @latitude, @longitude, @name, @radius = id, latitude, \
|
954
|
+
longitude, name, radius
|
955
|
+
|
956
|
+
end
|
957
|
+
|
958
|
+
def to_h()
|
959
|
+
|
960
|
+
{
|
961
|
+
id: @id,
|
962
|
+
longitude: @longitude,
|
963
|
+
latitude: @latitude,
|
964
|
+
name: @name,
|
965
|
+
radius: @radius
|
966
|
+
}
|
967
|
+
|
900
968
|
end
|
901
969
|
|
902
970
|
end
|
@@ -1881,12 +1949,12 @@ end
|
|
1881
1949
|
#
|
1882
1950
|
class GeofenceTrigger < Trigger
|
1883
1951
|
|
1884
|
-
def initialize(
|
1952
|
+
def initialize( h={}, geofences: {})
|
1885
1953
|
|
1886
1954
|
if h[:name] then
|
1887
|
-
|
1888
|
-
found =
|
1889
|
-
h[:geofence_id] = found.id
|
1955
|
+
puts ('geofences2: ' + geofences.inspect)
|
1956
|
+
found = geofences.find {|x| x.name.downcase == h[:name].downcase}
|
1957
|
+
h[:geofence_id] = found.id if found
|
1890
1958
|
|
1891
1959
|
end
|
1892
1960
|
|
@@ -1899,15 +1967,25 @@ class GeofenceTrigger < Trigger
|
|
1899
1967
|
}
|
1900
1968
|
|
1901
1969
|
super(options.merge filter(options, h))
|
1902
|
-
@
|
1970
|
+
@geofences = geofences
|
1903
1971
|
|
1904
1972
|
end
|
1905
1973
|
|
1906
1974
|
def to_s()
|
1907
1975
|
|
1908
|
-
|
1976
|
+
if $debug then
|
1977
|
+
puts ' @geofences: ' + @geofences.inspect
|
1978
|
+
puts '@h: ' + @h.inspect
|
1979
|
+
puts '@h[:geofence_id]: ' + @h[:geofence_id].inspect
|
1980
|
+
end
|
1981
|
+
|
1909
1982
|
direction = @h[:enter_area] ? 'Entry' : 'Exit'
|
1910
|
-
|
1983
|
+
|
1984
|
+
found = @geofences.find {|x| x.id == @h[:geofence_id]}
|
1985
|
+
puts 'found: ' + found.inspect
|
1986
|
+
label = found ? found.name : 'error: name not found'
|
1987
|
+
|
1988
|
+
"Geofence %s (%s)" % [direction, label]
|
1911
1989
|
|
1912
1990
|
end
|
1913
1991
|
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|