eyecare 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 85d920f2c46d050c6ba3b29fba3ffc550acb12e2
4
+ data.tar.gz: 33d3b57878150831a4cf21ab6fae141ebfa92c20
5
+ SHA512:
6
+ metadata.gz: 355fe3521265956c8346cb45e97ada8ae5fd2d3939516a1c9b76704623843d03615178d01fa1f28f4ac7a92a9f792d8e2f222456cb02f6ca4ef89582a1ca8437
7
+ data.tar.gz: f28106bc7f99d3b073fdd058a11dd44b25f5b22a3a7b3457db312d128ddbbf1a78ee0ee69b8fe0707df42184eb863a858515916b92e095f4262b4d62144559a3
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ tags
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eyecare.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Viorel Craescu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Eyecare
2
+
3
+ Reminds you to look away to avoid computer eye strain.
4
+ It is recommended to look away from your screen for 20 seconds every 20 minutes.
5
+
6
+ ## Installation
7
+
8
+ $ gem install eyecare
9
+
10
+ ## Usage
11
+
12
+ $ eyecare
13
+
14
+ Create a config file ~/.eyecare.
15
+
16
+ Config options are:
17
+
18
+ alert.message = 'Your message here'
19
+ alert.timeout = 20 # timeout in seconds
20
+ alert.interval = 20 * 60 # show up every 20 minutes
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/*_test.rb']
8
+ end
9
+
10
+ desc 'Run tests'
11
+ task :default => :test
data/bin/eyecare ADDED
@@ -0,0 +1,6 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'eyecare'
4
+
5
+ # runs as daemon
6
+ Eyecare::run!
data/eyecare.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eyecare/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eyecare"
8
+ spec.version = Eyecare::VERSION
9
+ spec.authors = ["Viorel Craescu"]
10
+ spec.email = ["viorel@craescu.com"]
11
+ spec.summary = %q{Protect your eyes}
12
+ spec.description = %q{Protect your eyes}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'libnotify'
22
+ spec.add_development_dependency 'bundler', '~> 1.5'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'minitest'
25
+ end
@@ -0,0 +1,69 @@
1
+ require 'libnotify'
2
+ require 'singleton'
3
+
4
+ module Eyecare
5
+ class Alert
6
+ include Singleton
7
+ attr_accessor :message
8
+ attr_accessor :timeout
9
+
10
+ DEFAULT_MESSAGE = 'Look away'
11
+ DEFAULT_TIMEOUT = 20
12
+
13
+ def init(options = {})
14
+ @message = options.fetch(:message, DEFAULT_MESSAGE)
15
+ @timeout = options.fetch(:timeout, DEFAULT_TIMEOUT)
16
+ self
17
+ end
18
+
19
+ def show
20
+ beep_start
21
+ notification.show!
22
+ run_after(self.timeout) { beep_end }
23
+ end
24
+
25
+ private
26
+ def initialize
27
+ self.init
28
+ end
29
+
30
+ def icon_path
31
+ File.join(Eyecare::IMAGES_PATH, 'eyecare.png')
32
+ end
33
+
34
+ def beep_start
35
+ play_audio('beep_start.wav')
36
+ end
37
+
38
+ def beep_end
39
+ play_audio('beep_end.wav')
40
+ end
41
+
42
+ def play_audio(filename)
43
+ audio_path = File.join(Eyecare::AUDIOS_PATH, filename)
44
+ pid = spawn("aplay #{audio_path} > /dev/null 2>&1")
45
+ Process.detach(pid)
46
+ end
47
+
48
+ def run_after(timeout, &block)
49
+ pid = fork do
50
+ sleep(timeout)
51
+ yield
52
+ end
53
+ Process.detach(pid)
54
+ end
55
+
56
+ def notification
57
+ Libnotify.new do |s|
58
+ s.summary = 'Eye Care'
59
+ s.body = self.message
60
+ s.timeout = self.timeout
61
+ s.urgency = :normal
62
+ s.icon_path = icon_path
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ #puts Eyecare::ASSETS_PATH
69
+ #Eyecare::Alert.new.show
Binary file
@@ -0,0 +1,43 @@
1
+ module Eyecare
2
+ class Config
3
+ attr_accessor :alert
4
+
5
+ def initialize
6
+ @alert = Alert.new
7
+ yield self if block_given?
8
+ end
9
+
10
+ def self.load_from_file(filename)
11
+ load_from_text(File.open(filename).read)
12
+ end
13
+
14
+ def self.load_from_text(text)
15
+ config = self.new
16
+ config.instance_eval do eval(text) end
17
+ config
18
+ end
19
+
20
+ def to_h
21
+ { alert: alert.to_hash }
22
+ end
23
+ end
24
+
25
+ class Eyecare::Config::Alert
26
+ attr_accessor :message
27
+ attr_accessor :timeout
28
+ attr_accessor :interval
29
+
30
+ def initialize
31
+ @timeout = 20
32
+ @interval = 20 * 60
33
+ end
34
+
35
+ def to_h
36
+ h = {}
37
+ h[:message] = self.message if self.message
38
+ h[:timeout] = self.timeout if self.timeout
39
+ h[:interval] = self.interval if self.interval
40
+ h
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Eyecare
2
+ VERSION = "0.0.1"
3
+ end
data/lib/eyecare.rb ADDED
@@ -0,0 +1,38 @@
1
+ require "eyecare/version"
2
+ require 'eyecare/alert'
3
+ require 'eyecare/config'
4
+
5
+ module Eyecare
6
+ ASSETS_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'eyecare', 'assets'))
7
+ IMAGES_PATH = File.join(ASSETS_PATH, 'images')
8
+ AUDIOS_PATH = File.join(ASSETS_PATH, 'audios')
9
+
10
+ class << self
11
+ def run!
12
+ Process.daemon
13
+ while true
14
+ sleep(config.alert.interval)
15
+ alert.show
16
+ end
17
+ end
18
+
19
+ def run
20
+ fork do
21
+ sleep(config.alert.interval)
22
+ alert.show
23
+ end
24
+ end
25
+
26
+ private
27
+ def alert
28
+ Alert.instance.init(config.alert.to_h)
29
+ end
30
+
31
+ def config
32
+ return @config if @config
33
+ config_file = File.expand_path('~/.eyecare')
34
+ @config = Config.load_from_file(config_file)
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+ require 'eyecare/alert'
3
+
4
+ describe Eyecare::Alert do
5
+ let(:config) do
6
+ { message: 'Blink blink', timeout: 40 }
7
+ end
8
+
9
+ it 'is defaulted is when no config' do
10
+ alert = Eyecare::Alert.instance
11
+ alert.message.wont_be_empty
12
+ alert.message.must_equal Eyecare::Alert::DEFAULT_MESSAGE
13
+ alert.timeout.must_equal Eyecare::Alert::DEFAULT_TIMEOUT
14
+ end
15
+
16
+ it 'is correctly initialized from config hash' do
17
+ alert = Eyecare::Alert.instance.init(config)
18
+
19
+ alert.message.wont_be_empty
20
+ alert.message.must_equal config[:message]
21
+ alert.timeout.must_equal config[:timeout]
22
+ end
23
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+ require 'eyecare/config'
3
+
4
+ describe Eyecare::Config do
5
+ it 'is initialize by a block' do
6
+ config = Eyecare::Config.new do |c|
7
+ c.alert.message = 'This is a test'
8
+ c.alert.timeout = 40
9
+ c.alert.interval = 30 * 60
10
+ end
11
+
12
+ config.alert.message.wont_be_empty
13
+ config.alert.timeout.must_equal 40
14
+ config.alert.interval.must_equal 30 * 60
15
+ end
16
+
17
+ it 'is loaded from text' do
18
+ text = %"
19
+ alert.message = 'This is a test message'
20
+ alert.timeout = 40
21
+ alert.interval = 30 * 60
22
+ "
23
+ config = Eyecare::Config.load_from_text(text)
24
+ config.alert.message.wont_be_empty
25
+ config.alert.timeout.must_equal 40
26
+ config.alert.interval.must_equal 30 * 60
27
+ end
28
+
29
+ it 'is loaded from file' do
30
+ text = %"
31
+ alert.message = 'This is a test message'
32
+ alert.timeout = 60
33
+ alert.interval = 40 * 60
34
+ "
35
+ require 'tempfile'
36
+ f = Tempfile.new('config')
37
+ f.write(text)
38
+ f.close
39
+
40
+ config = Eyecare::Config.load_from_file(f.path)
41
+ f.unlink
42
+ config.alert.message.wont_be_empty
43
+ config.alert.timeout.must_equal 60
44
+ config.alert.interval.must_equal 40 * 60
45
+ end
46
+ end
47
+
@@ -0,0 +1,2 @@
1
+ require 'minitest/autorun'
2
+ require 'eyecare'
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eyecare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Viorel Craescu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: libnotify
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Protect your eyes
70
+ email:
71
+ - viorel@craescu.com
72
+ executables:
73
+ - eyecare
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/eyecare
83
+ - eyecare.gemspec
84
+ - lib/eyecare.rb
85
+ - lib/eyecare/alert.rb
86
+ - lib/eyecare/assets/audios/beep_end.wav
87
+ - lib/eyecare/assets/audios/beep_start.wav
88
+ - lib/eyecare/assets/images/eye.png
89
+ - lib/eyecare/assets/images/eyecare.png
90
+ - lib/eyecare/config.rb
91
+ - lib/eyecare/version.rb
92
+ - test/alert_test.rb
93
+ - test/config_test.rb
94
+ - test/test_helper.rb
95
+ homepage: ''
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Protect your eyes
119
+ test_files:
120
+ - test/alert_test.rb
121
+ - test/config_test.rb
122
+ - test/test_helper.rb