comrade 0.0.2 → 0.0.4

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.
data/Gemfile CHANGED
@@ -1,9 +1,11 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  source "http://rubygems.org"
2
- source "http://gems.github.com"
3
4
 
4
- gem 'treetop', '~> 1.4.9'
5
+ gem 'treetop', '~> 1.4.9'
5
6
  gem 'ruby-dzen', '~> 0.0.1'
7
+ gem 'notifier', '~> 0.1.2'
6
8
 
7
9
  group :development, :test do
8
- gem 'rspec', '~> 2.2'
10
+ gem 'rspec', '~> 2.5.0'
9
11
  end
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
- remote: http://gems.github.com/
4
3
  specs:
5
4
  diff-lcs (1.1.2)
5
+ notifier (0.1.2)
6
6
  polyglot (0.3.1)
7
- rspec (2.2.0)
8
- rspec-core (~> 2.2)
9
- rspec-expectations (~> 2.2)
10
- rspec-mocks (~> 2.2)
11
- rspec-core (2.2.1)
12
- rspec-expectations (2.2.0)
7
+ rspec (2.5.0)
8
+ rspec-core (~> 2.5.0)
9
+ rspec-expectations (~> 2.5.0)
10
+ rspec-mocks (~> 2.5.0)
11
+ rspec-core (2.5.1)
12
+ rspec-expectations (2.5.0)
13
13
  diff-lcs (~> 1.1.2)
14
- rspec-mocks (2.2.0)
14
+ rspec-mocks (2.5.0)
15
15
  ruby-dzen (0.0.1)
16
16
  treetop (1.4.9)
17
17
  polyglot (>= 0.3.1)
@@ -20,6 +20,7 @@ PLATFORMS
20
20
  ruby
21
21
 
22
22
  DEPENDENCIES
23
- rspec (~> 2.2)
23
+ notifier (~> 0.1.2)
24
+ rspec (~> 2.5.0)
24
25
  ruby-dzen (~> 0.0.1)
25
26
  treetop (~> 1.4.9)
data/README.rdoc CHANGED
@@ -0,0 +1,38 @@
1
+ = About
2
+
3
+ Comrade is a simple visual timer on top of dzen2.
4
+ It draws a line on the top of your screen that progressively shrinks when the time passes.
5
+
6
+ = Installing and Usage
7
+
8
+ gem install comrade
9
+
10
+ To use just pass the time period you would like:
11
+
12
+ comrade 25m
13
+ comrade 5 minutes
14
+ comrade 60 seconds
15
+ comrade 24 hours
16
+ comrade 1 second
17
+ comrade 3s
18
+
19
+ dzen2 binary is an external dependency, http://sites.google.com/site/gotmor/dzen
20
+
21
+ = Maintainer
22
+
23
+ * Renan Mendes Carvalho https://github.com/aitherios/comrade
24
+
25
+ = License
26
+
27
+ This program is free software: you can redistribute it and/or modify
28
+ it under the terms of the GNU General Public License as published by
29
+ the Free Software Foundation, either version 3 of the License, or
30
+ (at your option) any later version.
31
+
32
+ This program is distributed in the hope that it will be useful,
33
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
34
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35
+ GNU General Public License for more details.
36
+
37
+ You should have received a copy of the GNU General Public License
38
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  require 'fileutils'
4
- require 'lib/version'
5
4
  require 'rubygems'
6
5
  require 'rspec/core/rake_task'
7
6
 
7
+ base_path = File.expand_path File.dirname(__FILE__)
8
+ require File.join(base_path, 'lib', 'comrade', 'version')
9
+
8
10
  RSpec::Core::RakeTask.new
9
11
 
10
12
  desc 'Build gem'
data/TODO CHANGED
@@ -1,4 +1,8 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- * adding comentaries to comrade
3
+ * adding comentaries to comrade binary
4
4
  * RDoc
5
+ * add a overview comentary to the comrade module
6
+ * add flags to control some behaviour
7
+ * add a help and usage message
8
+ * keep https://github.com/fnando/notifier in mind
data/bin/comrade CHANGED
@@ -3,24 +3,47 @@
3
3
 
4
4
  require 'rubygems'
5
5
  require 'dzen'
6
- require 'comrade'
6
+ require 'notifier'
7
+ require 'comrade/timer'
8
+ require 'comrade/optparse'
9
+
10
+ @options_hash = Comrade::Optparse.parse! ARGV
11
+ @timer = Comrade::Timer.new @options_hash[:timer] if @options_hash[:timer]
12
+
13
+ puts @options_hash[:message] unless @options_hash[:quiet]
14
+ exit if @options_hash[:exit]
7
15
 
8
16
  configure do |c|
9
17
  c.interval = 2
10
- c.output = IO.popen('dzen2 -h 1 -ta l -bg black -w 1280', 'w')
18
+ c.output = IO.popen(
19
+ 'dzen2' <<
20
+ " -h #{@options_hash[:thickness]}" <<
21
+ " -w #{@options_hash[:size]}" <<
22
+ " -x #{@options_hash[:xposition]}" <<
23
+ " -y #{@options_hash[:yposition]}" <<
24
+ ' -ta l' <<
25
+ " -bg #{@options_hash[:background_color]}" <<
26
+ " -fg #{@options_hash[:color]}" <<
27
+ ' -e "onstart=ungrabkeys,ungrabmouse;onnewinput=raise"',
28
+ 'w'
29
+ )
11
30
  end
12
31
 
13
32
  before_run do
14
- @timer = Comrade::Timer.new ARGV.join(' ').downcase
15
- puts 'Started at ' << DateTime.now.to_s
33
+ puts 'Started @ ' << Time.now.to_s unless @options_hash[:quiet]
16
34
  end
17
35
 
18
36
  app :line do
19
- if @timer.elapsed?
20
- puts 'Stopped at ' << DateTime.now.to_s
37
+ if @timer.finished? and @timer.loop?
38
+ Notifier.notify :title => 'comrade', :message => ARGV.join(' ')
39
+ puts 'Another loop @ ' << Time.now.to_s unless @options_hash[:quiet]
40
+ @timer = Comrade::Timer.new @options_hash[:timer]
41
+ elsif @timer.finished?
42
+ Notifier.notify :title => 'comrade', :message => ARGV.join(' ')
43
+ echo 'Stopped @ ' << Time.now.to_s
21
44
  Process.kill('INT', $$)
22
- else
23
- line_width = (@timer.remaining_ratio * 1280).round
24
- "^fg(red)^r(#{line_width}x1)"
25
45
  end
46
+
47
+ line_size = (@timer.remaining_ratio * @options_hash[:size].to_f).round
48
+ "^r(#{line_size}x#{@options_hash[:thickness]})"
26
49
  end
data/comrade.gemspec CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env gem build
2
2
  # -*- encoding: utf-8 -*-
3
3
 
4
- require 'lib/version'
4
+ base_path = File.expand_path File.dirname(__FILE__)
5
+ require File.join(base_path, 'lib', 'comrade', 'version')
5
6
 
6
7
  Gem::Specification.new do |g|
7
8
  g.name = 'comrade'
@@ -9,20 +10,21 @@ Gem::Specification.new do |g|
9
10
  g.author = 'Renan Mendes Carvalho'
10
11
  g.email = 'aitherios@gmail.com'
11
12
  g.homepage = 'http://github.com/aitherios/comrade'
13
+ g.license = 'GPL-3'
12
14
  g.summary = 'Simple visual timer on top of dzen2.'
13
15
  g.description = 'Comrade is a simple visual timer on top of dzen2.' <<
14
- 'It draws a line on your screen that progressively shrinks when the time passes.'
15
- g.cert_chain = nil
16
- g.rubyforge_project = 'Comrade'
16
+ ' It draws a line on your screen that progressively shrinks when the time passes.' <<
17
+ ' After that it notifies you when the time is over.'
17
18
 
18
19
  g.files = `git ls-files`.split("\n")
20
+ g.test_files = Dir.glob('spec/**/*_spec.rb')
19
21
  g.executables = Dir['bin/*'].map(&File.method(:basename))
20
- g.require_path = 'lib'
21
22
 
22
23
  g.required_ruby_version = ::Gem::Requirement.new '> 1.8'
23
24
  g.add_dependency 'treetop', '~> 1.4.9'
24
25
  g.add_dependency 'ruby-dzen', '~> 0.0.1'
26
+ g.add_dependency 'notifier', '~> 0.1.2'
25
27
  g.add_development_dependency 'bundler', '~> 1.0'
26
- g.add_development_dependency 'rspec', '~> 2.2'
28
+ g.add_development_dependency 'rspec', '~> 2.5.0'
27
29
  g.requirements << 'dzen2, tested with version 0.8.5, http://sites.google.com/site/gotmor/dzen'
28
30
  end
@@ -0,0 +1,81 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Comrade
4
+ require 'optparse'
5
+
6
+ base_path = File.expand_path File.dirname(__FILE__)
7
+ # Comrade version file
8
+ require File.join(base_path, 'version')
9
+
10
+ class Optparse
11
+ def self.parse! args
12
+ hash = {}
13
+ OptionParser.new do |opts|
14
+ opts.banner = 'Usage: comrade [options] [time]'
15
+
16
+ opts.separator ''
17
+ opts.separator 'Optional arguments:'
18
+
19
+ hash[:color] = 'red'
20
+ opts.on('-c', '--color COLOR', '--colour COLOR', String, 'Line color') do |color|
21
+ hash[:color] = color.strip
22
+ end
23
+
24
+ hash[:background_color] = 'black'
25
+ opts.on('-b', '--background COLOR', String, 'Line background color') do |color|
26
+ hash[:background_color] = color.strip
27
+ end
28
+
29
+ hash[:size] = `xrandr`.grep(/\*/)[0].match(/\d+/)[0]
30
+ opts.on('-s', '--size SIZE', Integer, 'Line size in pixels') do |size|
31
+ hash[:size] = size
32
+ end
33
+
34
+ hash[:thickness] = 1
35
+ opts.on('-t', '--thickness THICKNESS', Integer, 'Line thickness in pixels') do |thickness|
36
+ hash[:thickness] = thickness
37
+ end
38
+
39
+ hash[:xposition] = 0
40
+ opts.on('-x X', Integer, 'X axis position in pixels') do |x|
41
+ hash[:xposition] = x
42
+ end
43
+
44
+ hash[:yposition] = 0
45
+ opts.on('-y Y', Integer, 'Y axis position in pixels') do |y|
46
+ hash[:yposition] = y
47
+ end
48
+
49
+ opts.separator ''
50
+ opts.separator 'Common arguments:'
51
+
52
+ hash[:quiet] = false
53
+ opts.on_tail('-q', '--quiet', 'Keep quiet, doesn\'t print any text') do
54
+ hash[:quiet] = true
55
+ end
56
+
57
+ hash[:exit] = false
58
+ hash[:message] = ''
59
+
60
+ opts.on_tail('-h', '--help', 'Show this message') do
61
+ hash[:message] = opts.to_s
62
+ hash[:exit] = true
63
+ end
64
+
65
+ opts.on_tail('--version', 'Show version') do
66
+ hash[:message] = "comrade version #{Comrade::VERSION} \n\n" <<
67
+ "Copyright (C) 2010 Free Software Foundation, Inc.\n" <<
68
+ "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n" <<
69
+ "This is free software: you are free to change and redistribute it.\n" <<
70
+ "There is NO WARRANTY, to the extent permitted by law.\n" <<
71
+ "Written by Renan Mendes Carvalho.\n"
72
+ hash[:exit] = true
73
+ end
74
+ end.parse! args
75
+
76
+ hash[:timer] = args.join(' ') unless args.empty?
77
+
78
+ hash
79
+ end
80
+ end
81
+ end
@@ -1,73 +1,73 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- require 'date'
4
- class DateTime
5
- # Returns the Unix time, also know as POSIX time or Unix epoch.
6
- # The number of seconds elapsed since midnight of January 1, 1970 UTC
7
- # [return] Fixnum
8
- def unix_time
9
- strftime('%s').to_i
10
- end
11
- end
12
-
13
3
  module Comrade
14
- require 'version'
15
4
  require 'rubygems'
16
5
  require 'treetop'
17
6
 
18
7
  base_path = File.expand_path File.dirname(__FILE__)
19
8
  # Treetop grammar used to parse time period inputs
20
- Treetop.load File.join(base_path, 'period_grammar.treetop')
9
+ Treetop.load File.join(base_path, '..', 'period_grammar.treetop')
10
+ # Comrade version file
11
+ require File.join(base_path, 'version')
12
+ # DateTime class append
13
+ require File.join(base_path, '..', 'date')
21
14
 
22
- class Timer
23
15
 
16
+ class Timer
24
17
  # Initializes the variables started_at and stops_at
25
18
  # [param] time_period_string string to be parsed by treetop
26
- def initialize time_period_string
27
- @started_at = DateTime.now
28
- @stops_at = @started_at + period_in_days(time_period_string)
19
+ def initialize string
20
+ @started_at = Time.now
21
+
22
+ @parsed = parse string
23
+ if @parsed.timestamp?
24
+ date = DateTime.parse "#{@parsed.input}#{@started_at.zone}"
25
+ @stops_at = date > @started_at ? date : date + 1
26
+ else
27
+ @stops_at = @started_at + @parsed.to_seconds
28
+ end
29
29
  end
30
30
 
31
31
  # Elapsed time ratio
32
- # Starts at 1.0 and goes down to 0.0
32
+ # Starts at 0.0 and goes up to 1.0
33
33
  # [return] Float
34
- def elapsed_ratio; elapsed_seconds.to_f / total_seconds.to_f end
34
+ def elapsed_ratio
35
+ ratio = elapsed_seconds.to_f / total_seconds.to_f
36
+ ratio > 1.0 ? 1.0 : ratio
37
+ end
35
38
 
36
39
  # Elapsed time percentage
37
- # Starts at 100 and goes down to 0
40
+ # Starts at 0 and goes up to 100
38
41
  # [return] Float
39
42
  def elapsed_percentage; elapsed_ratio * 100 end
40
43
 
41
44
  # Remaining time ratio
42
- # Starts at 0.0 and goes to 1.0
45
+ # Starts at 1.0 and goes down to 0.0
43
46
  # [return] Float
44
- def remaining_ratio; 1 - elapsed_ratio end
47
+ def remaining_ratio;1 - elapsed_ratio end
45
48
 
46
49
  # Remaining time percentage
47
- # Starts at 0 and goes down to 100
50
+ # Starts at 100 and goes down to 0
48
51
  # [return] Float
49
52
  def remaining_percentage; remaining_ratio * 100 end
50
53
 
51
54
  # Return if the time has elapsed
52
- def elapsed?
53
- DateTime.now >= @stops_at
54
- end
55
+ def elapsed?; elapsed_ratio >= 1.0 end
55
56
  alias :finished? :elapsed?
56
57
 
58
+ # Timer should loop
59
+ def loop?
60
+ @parsed.loop?
61
+ end
62
+
57
63
  private
58
64
 
59
- def period_in_days time_period_string
60
- parsed = PeriodParser.new.parse time_period_string
61
-
65
+ # Parses the input using the PeriodParser
66
+ # raises 'Parsing Error' if parsing unsuccessful
67
+ def parse string
68
+ parsed = PeriodParser.new.parse string
62
69
  raise 'Parsing Error' if parsed.nil?
63
-
64
- if parsed.time_unit.second?
65
- parsed.number.text_value.to_f / 86400
66
- elsif parsed.time_unit.minute?
67
- parsed.number.text_value.to_f / 1440
68
- elsif parsed.time_unit.hour?
69
- parsed.number.text_value.to_f / 24
70
- end
70
+ parsed
71
71
  end
72
72
 
73
73
  # Seconds between timer start and expected end
@@ -79,7 +79,7 @@ module Comrade
79
79
  # Elapsed seconds since timer started
80
80
  # [return] Fixnum
81
81
  def elapsed_seconds
82
- DateTime.now.unix_time - @started_at.unix_time
82
+ Time.now.unix_time - @started_at.unix_time
83
83
  end
84
84
 
85
85
  end
@@ -0,0 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Comrade
4
+ VERSION = '0.0.4' unless constants.include? 'VERSION'
5
+ end
data/lib/date.rb ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'date'
4
+
5
+ class DateTime
6
+ # Returns the Unix time, also know as POSIX time or Unix epoch.
7
+ # The number of seconds elapsed since midnight of January 1, 1970 UTC
8
+ # [return] Fixnum
9
+ def unix_time
10
+ strftime('%s').to_f
11
+ end
12
+ end
13
+
14
+ class Time
15
+ # Returns the Unix time, also know as POSIX time or Unix epoch.
16
+ # The number of seconds elapsed since midnight of January 1, 1970 UTC
17
+ # [return] Fixnum
18
+ def unix_time
19
+ strftime('%s').to_f
20
+ end
21
+ end
@@ -3,17 +3,61 @@
3
3
  grammar Period
4
4
 
5
5
  rule period
6
- [\s]* number [\s]* time_unit
6
+ (
7
+ number
8
+ [\s]*
9
+ time_unit
10
+ [\s]*
11
+ loop:loop?
12
+ {
13
+ def timestamp?; false end
14
+
15
+ def to_seconds
16
+ if time_unit.second?
17
+ number.text_value.to_f
18
+ elsif time_unit.minute?
19
+ number.text_value.to_f * 60
20
+ elsif time_unit.hour?
21
+ number.text_value.to_f * 60 * 24
22
+ end
23
+ end
24
+
25
+ def to_days
26
+ if time_unit.second?
27
+ number.text_value.to_f / 86400
28
+ elsif time_unit.minute?
29
+ number.text_value.to_f / 1440
30
+ elsif time_unit.hour?
31
+ number.text_value.to_f / 24
32
+ end
33
+ end
34
+
35
+ def loop?; not loop.text_value.empty? end
36
+ }
37
+ )
38
+ /
39
+ (
40
+ timestamp
41
+ {
42
+ def timestamp?; true end
43
+ }
44
+ )
7
45
  end
8
46
 
9
47
  rule number
10
- [0-9]+
48
+ [\d]+
11
49
  end
12
50
 
13
51
  rule time_unit
14
52
  second / minute / hour
15
53
  end
16
54
 
55
+ rule timestamp
56
+ hour:[\d]1..2 ':' minute:[\d]2..2
57
+ (':' second:[\d]2..2)?
58
+ ([\s]* 'am' / 'pm')?
59
+ end
60
+
17
61
  rule word_end
18
62
  !(!' ' .)
19
63
  end
@@ -21,9 +65,9 @@ grammar Period
21
65
  rule second
22
66
  (en_second / pt_second)
23
67
  {
24
- def second?; true; end
25
- def minute?; false; end
26
- def hour?; false; end
68
+ def second?; true end
69
+ def minute?; false end
70
+ def hour?; false end
27
71
  }
28
72
  end
29
73
 
@@ -54,9 +98,9 @@ grammar Period
54
98
  rule minute
55
99
  (en_minute / pt_minute)
56
100
  {
57
- def minute?; true; end
58
- def second?; false; end
59
- def hour?; false; end
101
+ def minute?; true end
102
+ def second?; false end
103
+ def hour?; false end
60
104
  }
61
105
  end
62
106
 
@@ -87,9 +131,9 @@ grammar Period
87
131
  rule hour
88
132
  (en_hour / pt_hour)
89
133
  {
90
- def hour?; true; end
91
- def second?; false; end
92
- def minute?; false; end
134
+ def hour?; true end
135
+ def second?; false end
136
+ def minute?; false end
93
137
  }
94
138
  end
95
139
 
@@ -109,4 +153,8 @@ grammar Period
109
153
  'h' word_end
110
154
  end
111
155
 
156
+ rule loop
157
+ 'loop'
158
+ end
159
+
112
160
  end
@@ -0,0 +1,184 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Comrade::Optparse do
6
+
7
+ describe 'parse' do
8
+
9
+ it { Comrade::Optparse.parse!(['']).should be_an_instance_of Hash }
10
+ it { Comrade::Optparse.parse!(['-h']).should be_an_instance_of Hash }
11
+
12
+ context 'when parsing help flag' do
13
+ context 'short style' do
14
+ subject { Comrade::Optparse.parse! ['-h'] }
15
+ its([:message]) { should be_an_instance_of String }
16
+ its([:message]) { should_not be_empty }
17
+ its([:exit]) { should be_true }
18
+ end
19
+
20
+ context 'long style' do
21
+ subject { Comrade::Optparse.parse! ['--help'] }
22
+ its([:message]) { should be_an_instance_of String }
23
+ its([:message]) { should_not be_empty }
24
+ its([:exit]) { should be_true }
25
+ end
26
+ end
27
+
28
+ context 'when parsing version flag' do
29
+ subject { Comrade::Optparse.parse! ['--version'] }
30
+ its([:message]) { should be_an_instance_of String }
31
+ its([:message]) { should_not be_empty }
32
+ its([:exit]) { should be_true }
33
+ end
34
+
35
+ describe '[:color]', 'line color flag' do
36
+ context 'short style' do
37
+ subject { Comrade::Optparse.parse! ['-c', 'blue'] }
38
+ its([:color]) { should be_an_instance_of String }
39
+ its([:color]) { should_not be_empty }
40
+ its([:color]) { should == 'blue' }
41
+ end
42
+
43
+ context 'long style' do
44
+ subject { Comrade::Optparse.parse! ['--color', 'blue'] }
45
+ its([:color]) { should be_an_instance_of String }
46
+ its([:color]) { should_not be_empty }
47
+ its([:color]) { should == 'blue' }
48
+ end
49
+
50
+ context 'long style, british spelling' do
51
+ subject { Comrade::Optparse.parse! ['--colour', 'blue'] }
52
+ its([:color]) { should be_an_instance_of String }
53
+ its([:color]) { should_not be_empty }
54
+ its([:color]) { should == 'blue' }
55
+ end
56
+
57
+ context 'default value' do
58
+ subject { Comrade::Optparse.parse! ['25m'] }
59
+ its([:color]) { should be_an_instance_of String }
60
+ its([:color]) { should_not be_empty }
61
+ its([:color]) { should == 'red' }
62
+ end
63
+ end
64
+
65
+ describe '[:size]', 'line size flag' do
66
+ context 'short style' do
67
+ subject { Comrade::Optparse.parse! ['-s', '250'] }
68
+ its([:size]) { should be_an_instance_of Fixnum }
69
+ its([:size]) { should == 250 }
70
+ end
71
+
72
+ context 'long style' do
73
+ subject { Comrade::Optparse.parse! ['--size', '250'] }
74
+ its([:size]) { should be_an_instance_of Fixnum }
75
+ its([:size]) { should == 250 }
76
+ end
77
+
78
+ context 'default value' do
79
+ subject { Comrade::Optparse.parse! ['25m'] }
80
+ its([:size]) { should be_an_instance_of Fixnum }
81
+ its([:size]) { should == 1280 }
82
+ end
83
+ end
84
+
85
+ describe '[:thickness]', 'line thickness flag' do
86
+ context 'short style' do
87
+ subject { Comrade::Optparse.parse! ['-t', '250'] }
88
+ its([:thickness]) { should be_an_instance_of Fixnum }
89
+ its([:thickness]) { should == 250 }
90
+ end
91
+
92
+ context 'long style' do
93
+ subject { Comrade::Optparse.parse! ['--thickness', '250'] }
94
+ its([:thickness]) { should be_an_instance_of Fixnum }
95
+ its([:thickness]) { should == 250 }
96
+ end
97
+
98
+ context 'default value' do
99
+ subject { Comrade::Optparse.parse! ['25m'] }
100
+ its([:thickness]) { should be_an_instance_of Fixnum }
101
+ its([:thickness]) { should == 1 }
102
+ end
103
+ end
104
+
105
+ describe '[:timer]', 'timer arguments' do
106
+ context 'without a loop' do
107
+ subject { Comrade::Optparse.parse! ['-t', '250', '25m'] }
108
+ its([:timer]) { should == '25m' }
109
+ end
110
+
111
+ context 'with a loop' do
112
+ subject { Comrade::Optparse.parse! ['-t', '250', '25m', 'loop'] }
113
+ its([:timer]) { should == '25m loop' }
114
+ end
115
+ end
116
+
117
+ describe '[:xposition]', 'screen x position flag' do
118
+ context 'short style' do
119
+ subject { Comrade::Optparse.parse! ['-x', '300'] }
120
+ its([:xposition]) { should be_an_instance_of Fixnum }
121
+ its([:xposition]) { should == 300 }
122
+ end
123
+
124
+ context 'default value' do
125
+ subject { Comrade::Optparse.parse! ['25m'] }
126
+ its([:xposition]) { should be_an_instance_of Fixnum }
127
+ its([:xposition]) { should == 0 }
128
+ end
129
+ end
130
+
131
+ describe '[:yposition]', 'screen x position flag' do
132
+ context 'short style' do
133
+ subject { Comrade::Optparse.parse! ['-y', '300'] }
134
+ its([:yposition]) { should be_an_instance_of Fixnum }
135
+ its([:yposition]) { should == 300 }
136
+ end
137
+
138
+ context 'default value' do
139
+ subject { Comrade::Optparse.parse! ['25m'] }
140
+ its([:yposition]) { should be_an_instance_of Fixnum }
141
+ its([:yposition]) { should == 0 }
142
+ end
143
+ end
144
+
145
+ describe '[:background_color]', 'line background color flag' do
146
+ context 'short style' do
147
+ subject { Comrade::Optparse.parse! ['-b', 'red'] }
148
+ its([:background_color]) { should be_an_instance_of String }
149
+ its([:background_color]) { should == 'red' }
150
+ end
151
+
152
+ context 'long style' do
153
+ subject { Comrade::Optparse.parse! ['--background', 'red'] }
154
+ its([:background_color]) { should be_an_instance_of String }
155
+ its([:background_color]) { should == 'red' }
156
+ end
157
+
158
+ context 'default value' do
159
+ subject { Comrade::Optparse.parse! ['25m'] }
160
+ its([:background_color]) { should be_an_instance_of String }
161
+ its([:background_color]) { should == 'black' }
162
+ end
163
+ end
164
+
165
+ describe '[:quiet]', 'quiet flag' do
166
+ context 'short style' do
167
+ subject { Comrade::Optparse.parse! ['-q', '25m'] }
168
+ its([:quiet]) { should be_true }
169
+ end
170
+
171
+ context 'long style' do
172
+ subject { Comrade::Optparse.parse! ['--quiet', '25m'] }
173
+ its([:quiet]) { should be_true }
174
+ end
175
+
176
+ context 'default value' do
177
+ subject { Comrade::Optparse.parse! ['25m'] }
178
+ its([:quiet]) { should be_false }
179
+ end
180
+ end
181
+
182
+ end
183
+
184
+ end
@@ -48,5 +48,19 @@ describe PeriodParser do
48
48
  it { should parse '1 hora' }
49
49
  it { should parse '2 horas' }
50
50
  end
51
+
52
+ context 'when parsing a timestamp' do
53
+ it { should parse '1:30' }
54
+ it { should parse '23:30' }
55
+ it { should parse '23:30:21' }
56
+ it { should parse '11:30 am' }
57
+ it { should parse '11:30pm' }
58
+ end
59
+
60
+ context 'when parsing a time period with the loop option' do
61
+ it { should parse '1 hour loop' }
62
+ it { should parse '25 minutes loop' }
63
+ end
64
+
51
65
  end
52
66
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- # requiring comrade module
4
3
  base_path = File.expand_path File.dirname(__FILE__)
5
- require File.join(base_path, '..', 'lib', 'comrade')
6
- # requiring support directory
7
- Dir[File.join base_path, 'support/**/*.rb'].each {|f| require f}
4
+ # comrade module
5
+ Dir[File.join base_path, '../lib/comrade/**/*.rb'].each { |f| require f }
6
+ # support directory
7
+ Dir[File.join base_path, 'support/**/*.rb'].each { |f| require f }
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ RSpec::Matchers.define :construct do |string, opts|
4
+ match do |object|
5
+ begin
6
+ object.new string
7
+ rescue
8
+ false
9
+ end
10
+ end
11
+
12
+ failure_message_for_should do |object|
13
+ "expected that #{object} would #{description}"
14
+ end
15
+
16
+ failure_message_for_should_not do |object|
17
+ "expected that #{object} would not #{description}"
18
+ end
19
+
20
+ description do
21
+ "be created with with '#{string}'"
22
+ end
23
+ end
@@ -5,11 +5,11 @@ RSpec::Matchers.define :parse do |string, opts|
5
5
  parser.parse(string) != nil
6
6
  end
7
7
 
8
- failure_message_for_should do |array|
8
+ failure_message_for_should do |parser|
9
9
  "expected that #{parser} would #{description}"
10
10
  end
11
11
 
12
- failure_message_for_should_not do |array|
12
+ failure_message_for_should_not do |parser|
13
13
  "expected that #{parser} would not #{description}"
14
14
  end
15
15
 
@@ -0,0 +1,75 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Comrade::Timer do
6
+
7
+ describe 'new' do
8
+ subject { Comrade::Timer }
9
+ it { should_not construct '' }
10
+ it { should construct '60 seconds' }
11
+ it { should construct '24h' }
12
+ it { should construct '13:37' }
13
+ it { should construct '25m loop' }
14
+ end
15
+
16
+ context 'beeing initialized with 10 seconds' do
17
+ before { @timer = Comrade::Timer.new '10 seconds' }
18
+ subject { @timer }
19
+
20
+ context 'when elapsed seconds is 0' do
21
+ before { @timer.should_receive(:elapsed_seconds).any_number_of_times.and_return(0) }
22
+ its(:elapsed_ratio) { should == 0.0 }
23
+ its(:elapsed_percentage) { should == 0 }
24
+ its(:remaining_ratio) { should == 1.0 }
25
+ its(:remaining_percentage) { should == 100 }
26
+ its(:elapsed?) { should be_false }
27
+ end
28
+
29
+ context 'when elapsed seconds is 5' do
30
+ before { @timer.should_receive(:elapsed_seconds).any_number_of_times.and_return(5) }
31
+ its(:elapsed_ratio) { should == 0.5 }
32
+ its(:elapsed_percentage) { should == 50 }
33
+ its(:remaining_ratio) { should == 0.5 }
34
+ its(:remaining_percentage) { should == 50 }
35
+ its(:elapsed?) { should be_false }
36
+ end
37
+
38
+ context 'when elapsed seconds is 10' do
39
+ before { @timer.should_receive(:elapsed_seconds).any_number_of_times.and_return(10) }
40
+ its(:elapsed_ratio) { should == 1.0 }
41
+ its(:elapsed_percentage) { should == 100 }
42
+ its(:remaining_ratio) { should == 0.0 }
43
+ its(:remaining_percentage) { should == 0 }
44
+ its(:elapsed?) { should be_true }
45
+ end
46
+
47
+ context 'when elapsed seconds greater than 10' do
48
+ before { @timer.should_receive(:elapsed_seconds).any_number_of_times.and_return(12) }
49
+ its(:elapsed_ratio) { should == 1.0 }
50
+ its(:elapsed_percentage) { should == 100 }
51
+ its(:remaining_ratio) { should == 0.0 }
52
+ its(:remaining_percentage) { should == 0 }
53
+ its(:elapsed?) { should be_true }
54
+ end
55
+ end
56
+
57
+ context 'when concerning the loop option' do
58
+ context 'present' do
59
+ before { @timer = Comrade::Timer.new '10 seconds loop' }
60
+ subject { @timer }
61
+
62
+ it { should respond_to :loop? }
63
+ its(:loop?) { should be_true }
64
+ end
65
+
66
+ context 'missing' do
67
+ before { @timer = Comrade::Timer.new '10 seconds' }
68
+ subject { @timer }
69
+
70
+ it { should respond_to :loop? }
71
+ its(:loop?) { should be_false }
72
+ end
73
+ end
74
+
75
+ end
metadata CHANGED
@@ -1,28 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comrade
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 23
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 2
9
- version: 0.0.2
9
+ - 4
10
+ version: 0.0.4
10
11
  platform: ruby
11
12
  authors:
12
13
  - Renan Mendes Carvalho
13
14
  autorequire:
14
15
  bindir: bin
15
- cert_chain:
16
- date: 2011-01-27 00:00:00 -02:00
17
- default_executable:
16
+ cert_chain: []
17
+
18
+ date: 2011-07-29 00:00:00 Z
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
20
21
  name: treetop
21
22
  prerelease: false
22
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
23
25
  requirements:
24
26
  - - ~>
25
27
  - !ruby/object:Gem::Version
28
+ hash: 21
26
29
  segments:
27
30
  - 1
28
31
  - 4
@@ -34,9 +37,11 @@ dependencies:
34
37
  name: ruby-dzen
35
38
  prerelease: false
36
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
37
41
  requirements:
38
42
  - - ~>
39
43
  - !ruby/object:Gem::Version
44
+ hash: 29
40
45
  segments:
41
46
  - 0
42
47
  - 0
@@ -45,36 +50,56 @@ dependencies:
45
50
  type: :runtime
46
51
  version_requirements: *id002
47
52
  - !ruby/object:Gem::Dependency
48
- name: bundler
53
+ name: notifier
49
54
  prerelease: false
50
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
51
57
  requirements:
52
58
  - - ~>
53
59
  - !ruby/object:Gem::Version
60
+ hash: 31
61
+ segments:
62
+ - 0
63
+ - 1
64
+ - 2
65
+ version: 0.1.2
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: bundler
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ hash: 15
54
77
  segments:
55
78
  - 1
56
79
  - 0
57
80
  version: "1.0"
58
81
  type: :development
59
- version_requirements: *id003
82
+ version_requirements: *id004
60
83
  - !ruby/object:Gem::Dependency
61
84
  name: rspec
62
85
  prerelease: false
63
- requirement: &id004 !ruby/object:Gem::Requirement
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
64
88
  requirements:
65
89
  - - ~>
66
90
  - !ruby/object:Gem::Version
91
+ hash: 27
67
92
  segments:
68
93
  - 2
69
- - 2
70
- version: "2.2"
94
+ - 5
95
+ - 0
96
+ version: 2.5.0
71
97
  type: :development
72
- version_requirements: *id004
73
- description: Comrade is a simple visual timer on top of dzen2.It draws a line on your screen that progressively shrinks when the time passes.
98
+ version_requirements: *id005
99
+ description: Comrade is a simple visual timer on top of dzen2. It draws a line on your screen that progressively shrinks when the time passes. After that it notifies you when the time is over.
74
100
  email: aitherios@gmail.com
75
101
  executables:
76
102
  - comrade
77
- - comrade~
78
103
  extensions: []
79
104
 
80
105
  extra_rdoc_files: []
@@ -91,42 +116,52 @@ files:
91
116
  - bin/comrade
92
117
  - comrade.gemspec
93
118
  - gpl-3.0.txt
94
- - lib/comrade.rb
119
+ - lib/comrade/optparse.rb
120
+ - lib/comrade/timer.rb
121
+ - lib/comrade/version.rb
122
+ - lib/date.rb
95
123
  - lib/period_grammar.treetop
96
- - lib/version.rb
124
+ - spec/optparse_spec.rb
97
125
  - spec/period_grammar_spec.rb
98
126
  - spec/spec_helper.rb
127
+ - spec/support/construct_matcher.rb
99
128
  - spec/support/parse_matcher.rb
100
- has_rdoc: true
129
+ - spec/timer_spec.rb
101
130
  homepage: http://github.com/aitherios/comrade
102
- licenses: []
103
-
131
+ licenses:
132
+ - GPL-3
104
133
  post_install_message:
105
134
  rdoc_options: []
106
135
 
107
136
  require_paths:
108
137
  - lib
109
138
  required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
110
140
  requirements:
111
141
  - - ">"
112
142
  - !ruby/object:Gem::Version
143
+ hash: 31
113
144
  segments:
114
145
  - 1
115
146
  - 8
116
147
  version: "1.8"
117
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
118
150
  requirements:
119
151
  - - ">="
120
152
  - !ruby/object:Gem::Version
153
+ hash: 3
121
154
  segments:
122
155
  - 0
123
156
  version: "0"
124
157
  requirements:
125
158
  - dzen2, tested with version 0.8.5, http://sites.google.com/site/gotmor/dzen
126
- rubyforge_project: Comrade
127
- rubygems_version: 1.3.6
159
+ rubyforge_project:
160
+ rubygems_version: 1.7.2
128
161
  signing_key:
129
162
  specification_version: 3
130
163
  summary: Simple visual timer on top of dzen2.
131
- test_files: []
132
-
164
+ test_files:
165
+ - spec/timer_spec.rb
166
+ - spec/optparse_spec.rb
167
+ - spec/period_grammar_spec.rb
data/bin/comrade~ DELETED
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- require 'rubygems'
5
- require 'dzen'
6
-
7
- include DZEN::Helpers
8
-
9
- # configure the output
10
- # these are the defaults,
11
- # change them if necessary, otherwise you can remove this block
12
- # `interval` and `output` are just two possible options,
13
- # see dzen/base.rb for more options
14
- configure do |c|
15
- c.interval = 3
16
-
17
- # output can be anything,
18
- # just make sure it has #puts and #print
19
- writeme = IO.popen("dzen2", "w")
20
- c.output = writeme
21
- end
22
-
23
- before_run do
24
- "--- loading ---#{DZEN::Base::Config[:ending]}"
25
- end
26
-
27
- # change order if necessary
28
- # without this the apps are displayed in the order they are defined
29
- # if an app is defined but not in this order list,
30
- # it wont be displayed at all
31
- #order :pidgin, :gajim, :loadavg
32
-
33
- # each little app has to return a string to be displayed
34
-
35
- # show hdd temperature
36
- # the hddtemp daemon should be running
37
- app :hdd_temp do
38
- "HDD: #{`nc localhost 7634`.split(/\|/)[-2]}°C"
39
- end
40
-
41
- # show cpu temperature using the `sensors` program
42
- # and display the current frequency
43
- app :cpu do
44
- "CPU: #{`sensors`.scan(/Core \d:\s+\+(\d+)\.\d/).flatten.map{|e|"#{e}°C"}.join("/")} " +
45
- IO.read("/proc/cpuinfo").scan(/^cpu MHz\s+:\s+(\d+)/).flatten.map{|e|"%.1fGhz" % (e.to_i/1000.0)}.join("/")
46
- end
47
-
48
- # display the current load average
49
- app :loadavg do
50
- IO.read('/proc/loadavg').split(/ /)[0,3].join(' ')
51
- end
52
-
53
- # display the time
54
- app :time do
55
- Time.now.strftime("%d.%m.%Y %H:%M")
56
- end
data/lib/version.rb DELETED
@@ -1,5 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- module Comrade
4
- VERSION = "0.0.2"
5
- end