clock_window 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1eeb75045c84292f96dc765b06173d5c43afe5e0
4
- data.tar.gz: 908fd15c3d7c4beba0dfb4bf497e19147aa99612
3
+ metadata.gz: 5012765917a148b032d0ba2d0500799e4f755f3c
4
+ data.tar.gz: 4753ccc37be96da66166b90a683c2c08c3cad383
5
5
  SHA512:
6
- metadata.gz: 7bd7995f99f8d5aee5d81b5fb58fa8f1b0e129c53d1d4840a3f6638a3d13fbb777884765d45c55a1eef106c8bcff0001928dc28d30df258b7f94ef4f5e119fca
7
- data.tar.gz: fbcdecdde1147191822d8c0d6ee9c40bd46e12c7cea0e03a70cf3707d66bc8e2eeae3f32626afee406739867b3c497a86690827f024c83a2ee720623f413e172
6
+ metadata.gz: d4794cfd6ebec829de70e8ef42a6c6901ffd3b2cbdcdbbc7669a22374fc075bcda2eb36e7e3d1dafb470ff117319e0487bdd650b3b432655e6a47015aed440ed
7
+ data.tar.gz: 615416ae0e711751cefed115c9848e090a919c8f3f40ea39c0896fa29973a6d4a95eabd1709a1d68b9ae2f1b7428683383a2948e2a93f9e8566acd8d439a4fcf
data/.travis.yml CHANGED
@@ -2,4 +2,5 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.3.1
5
- before_install: gem install bundler -v 1.12.1
5
+ before_install: gem install bundler -v 1.12.3
6
+ script: XWINDOWS=FALSE bundle exec rake test
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Build Status](https://travis-ci.org/danielpclark/clock_window.svg?branch=master)](https://travis-ci.org/danielpclark/clock_window)
1
2
  [![Code Triagers Badge](http://www.codetriage.com/danielpclark/clock_window/badges/users.svg)](http://www.codetriage.com/danielpclark/clock_window)
2
3
 
3
4
  # Clock Window
@@ -0,0 +1,48 @@
1
+ module ClockWindow
2
+ class Filters
3
+ def initialize(**kwargs)
4
+ @title_range = kwargs.fetch(:title_range) { 0..60 }
5
+ @lazy_matchers = kwargs.fetch(:lazy_matchers) { true }
6
+ @no_notify = kwargs.fetch(:no_notify) { false }
7
+
8
+ # These are destructive matchers. String will conform to match data.
9
+ @matches = Array(kwargs.fetch(:matches) { [] }) # [/(thing)/, /(in)/] # parenthesis takes priority
10
+ @substitutions = Array(kwargs.fetch(:substitutions) { [] }) # [[//,'']]
11
+ end
12
+
13
+ def call(source)
14
+ apply_filters(source)
15
+ end
16
+
17
+ private
18
+ def apply_filters(target)
19
+ target = matchers(target)
20
+ @substitutions.each do |a,b|
21
+ target = target.gsub(a,b)
22
+ end
23
+ target = no_notify(target)
24
+ target[@title_range]
25
+ end
26
+
27
+ def matchers(target)
28
+ @matches.each do |fltr|
29
+ if @lazy_matchers
30
+ tmp = target.match( Regexp.new(fltr) )
31
+ tmp = tmp[1] || tmp[0] if tmp.is_a? MatchData
32
+ target = tmp || target
33
+ else
34
+ target = target[Regexp.new(fltr)].to_s
35
+ end
36
+ end
37
+ target
38
+ end
39
+
40
+ def no_notify(target)
41
+ # Remove Twitter notifications (must be last)
42
+ # Other sites may follow same notification pattern
43
+ target = target.gsub(Regexp.new(/\A ?\(\d+\) ?/), '') if @no_notify
44
+ target
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,61 @@
1
+ module ClockWindow
2
+ class OScommand
3
+ using Refinements::AddIf
4
+ # As this will get more sophisticated this class is the Back End
5
+ def initialize(**kwargs)
6
+ @filter_opts = kwargs.fetch(:filter_opts) { {} }
7
+
8
+ # Detect operating system
9
+ @os = RbConfig::CONFIG['host_os']
10
+ end
11
+
12
+ # output will be a two parameter array
13
+ # the first will be an OS specific executable string
14
+ # the second will be formatting the return value from the executables output
15
+ def active_window
16
+ # Choose script to execute and format output to just window name
17
+ case @os
18
+ when /linux/i
19
+ # Linux command to execute
20
+ exe = "xprop -id $(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2) _NET_WM_NAME"
21
+
22
+ # Filters for resulting string
23
+ format = Filters.new(
24
+ matches: [ Regexp.new(/.*\"(.*)\"\n\z/) ].
25
+ add_if(@filter_opts.has_key? :matches){@filter_opts.delete(:matches)},
26
+ **@filter_opts
27
+ )
28
+ [exe, format]
29
+ when /darwin/i
30
+ exe = <<-SCRIPT
31
+ osascript -e '
32
+ global frontApp, frontAppName, windowTitle
33
+
34
+ set windowTitle to ""
35
+ tell application "System Events"
36
+ set frontApp to first application process whose frontmost is true
37
+ set frontAppName to name of frontApp
38
+ tell process frontAppName
39
+ tell (1st window whose value of attribute "AXMain" is true)
40
+ set windowTitle to value of attribute "AXTitle"
41
+ end tell
42
+ end tell
43
+ end tell
44
+
45
+ return windowTitle & " - " & frontAppName
46
+ '
47
+ SCRIPT
48
+
49
+ format = Filters.new(
50
+ matches: [ Regexp.new(/(.*)\n/) ].
51
+ add_if(@filter_opts.has_key? :matches){@filter_opts.delete(:matches)},
52
+ **@filter_opts
53
+ )
54
+ [exe, format]
55
+ else
56
+ raise "Not implemented for #{@os}"
57
+ end
58
+ end
59
+ end
60
+ private_constant :OScommand
61
+ end
@@ -0,0 +1,12 @@
1
+ module ClockWindow
2
+ module Refinements
3
+ module AddIf
4
+ refine Array do
5
+ def add_if(expr)
6
+ self.insert(-1, *Array(yield)) if expr
7
+ self
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module ClockWindow
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/clock_window.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  require "clock_window/version"
2
+ require "clock_window/refinements"
3
+ require "clock_window/filters"
4
+ require "clock_window/oscommand"
2
5
 
3
6
  module ClockWindow
4
7
  class ClockIt
5
8
  # As this will get more sophisticated this class is the UI
6
- def initialize
7
- @os_cmd = OScommand.new
9
+ def initialize(**kwargs)
10
+ @os_cmd = OScommand.new(**kwargs)
8
11
  end
9
12
 
10
13
  def active_window
@@ -12,54 +15,4 @@ module ClockWindow
12
15
  format.call(`#{exe}`)
13
16
  end
14
17
  end
15
-
16
- class OScommand
17
- # As this will get more sophisticated this class is the Back End
18
- def initialize
19
- # Detect operating system
20
- @os = RbConfig::CONFIG['host_os']
21
- @window_title_length = 0..60
22
- end
23
-
24
- # output will be a two parameter array
25
- # the first will be an OS specific executable string
26
- # the second will be formatting the return value from the executables output
27
- def active_window
28
- # Choose script to execute and format output to just window name
29
- case @os
30
- when /linux/i
31
- exe = "xprop -id $(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2) _NET_WM_NAME"
32
- format = ->str{ str.match(/.*\"(.*)\"\n\z/)[1][@window_title_length] }
33
- [exe, format]
34
- when /darwin/i
35
- exe = <<-SCRIPT
36
- osascript -e '
37
- global frontApp, frontAppName, windowTitle
38
-
39
- set windowTitle to ""
40
- tell application "System Events"
41
- set frontApp to first application process whose frontmost is true
42
- set frontAppName to name of frontApp
43
- tell process frontAppName
44
- tell (1st window whose value of attribute "AXMain" is true)
45
- set windowTitle to value of attribute "AXTitle"
46
- end tell
47
- end tell
48
- end tell
49
-
50
- return {frontAppName, windowTitle}
51
- '
52
- SCRIPT
53
-
54
- format = ->str {
55
- app, window = str.split(',')
56
- "#{window.strip} - #{app.strip}"[@window_title_length]
57
- }
58
- [exe, format]
59
- else
60
- raise "Not implemented for #{@os}"
61
- end
62
- end
63
- end
64
- private_constant :OScommand
65
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clock_window
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-11 00:00:00.000000000 Z
11
+ date: 2016-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neatjson
@@ -85,6 +85,9 @@ files:
85
85
  - clock_window.gemspec
86
86
  - exe/clock_window
87
87
  - lib/clock_window.rb
88
+ - lib/clock_window/filters.rb
89
+ - lib/clock_window/oscommand.rb
90
+ - lib/clock_window/refinements.rb
88
91
  - lib/clock_window/version.rb
89
92
  homepage: https://github.com/danielpclark/clock_window
90
93
  licenses: