libnotify 0.1.1 → 0.1.2

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/.gitignore CHANGED
@@ -2,3 +2,4 @@ doc
2
2
  pkg
3
3
  coverage
4
4
  tags
5
+ .yardoc
data/README.rdoc CHANGED
@@ -11,14 +11,14 @@ Metrics[http://getcaliper.com/caliper/project?repo=http%3A%2F%2Fgemcutter.org%2F
11
11
  require 'libnotify'
12
12
 
13
13
  # Block syntax
14
- Libnotify.new do |notify|
14
+ n = Libnotify.new do |notify|
15
15
  notify.summary = "world"
16
16
  notify.body = "hello"
17
17
  notify.timeout = 1.5 # 1.5 (s), 1000 (ms), "2", nil, false
18
18
  notify.urgency = :critical # :low, :normal, :critical
19
19
  notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
20
- notify.show!
21
20
  end
21
+ n.show!
22
22
 
23
23
  # Hash syntax
24
24
  Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
data/Rakefile CHANGED
@@ -18,6 +18,7 @@ begin
18
18
 
19
19
  gem.add_development_dependency "riot", ">= 0.1.12.pre"
20
20
  gem.add_development_dependency "riot_notifier", ">= 0.0.7"
21
+ gem.add_development_dependency "yard"
21
22
 
22
23
  gem.test_files = Dir.glob('test/test_*.rb')
23
24
  end
@@ -38,15 +39,18 @@ Rake::TestTask.new(:test) do |test|
38
39
  test.verbose = true
39
40
  end
40
41
 
41
- # RDoc
42
- require 'rake/rdoctask'
43
- Rake::RDocTask.new do |rd|
44
- rd.title = "Riot Notifier"
45
- rd.main = "README.rdoc"
46
- rd.rdoc_files.include("README.rdoc", "lib/*.rb")
47
- rd.rdoc_dir = "doc"
42
+ # Yard
43
+ begin
44
+ require 'yard'
45
+ YARD::Rake::YardocTask.new
46
+ rescue LoadError
47
+ task :yardoc do
48
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
49
+ end
48
50
  end
49
51
 
52
+ desc "Alias for `rake yard`"
53
+ task :doc => :yard
50
54
 
51
55
  # Misc
52
56
  desc "Tag files for vim"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/lib/libnotify.rb CHANGED
@@ -3,14 +3,64 @@ require 'ffi'
3
3
  # Ruby bindings for libnotify using FFI.
4
4
  #
5
5
  # See README.rdoc for usage examples.
6
+ #
7
+ # @see README.rdoc
8
+ # @see Libnotify.new
9
+ # @author Peter Suschlik
6
10
  module Libnotify
7
11
 
8
- def self.new(*args, &block)
9
- API.new(*args, &block)
12
+ # Creates a notification.
13
+ #
14
+ # @example Block syntax
15
+ # n = Libnotify.new do |notify|
16
+ # notify.summary = "world"
17
+ # notify.body = "hello"
18
+ # notify.timeout = 1.5 # 1.5 (s), 1000 (ms), "2", nil, false
19
+ # notify.urgency = :critical # :low, :normal, :critical
20
+ # notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
21
+ # end
22
+ # n.show!
23
+ #
24
+ # @example Mixed syntax
25
+ # Libnotify.new(options) do |n|
26
+ # n.timeout = 1.5 # overrides :timeout in options
27
+ # n.show!
28
+ # end
29
+ #
30
+ # @param [Hash] aptions options creating a notification
31
+ # @option options [String] :summary (' ') summary/title of the notification
32
+ # @option options [String] :body (' ') the body
33
+ # @option options [Fixnum, Float, nil, FalseClass, String] :timeout (nil) display duration of the notification.
34
+ # Use +false+ or +nil+ for no timeout.
35
+ # @option options [Symbol] :urgency (:normal) the urgency of the notification.
36
+ # Possible values are: +:low+, +:normal+ and +:critical+
37
+ # @option options [String] :icon_path path the an icon displayed.
38
+ #
39
+ # @yield [notify] passes the notification object
40
+ # @yieldparam [API] notify the notification object
41
+ #
42
+ # @return [API] the notification object
43
+ def self.new(options={}, &block)
44
+ API.new(options, &block)
10
45
  end
11
46
 
12
- def self.show(*args, &block)
13
- API.show(*args, &block)
47
+ # Shows a notification. It takes the same +options+ as Libnotify.new.
48
+ #
49
+ # @example Block syntax
50
+ # Libnotify.show do |notify|
51
+ # notify.summary = "world"
52
+ # notify.body = "hello"
53
+ # notify.timeout = 1.5 # 1.5 (s), 1000 (ms), "2", nil, false
54
+ # notify.urgency = :critical # :low, :normal, :critical
55
+ # notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg"
56
+ # end
57
+ #
58
+ # @example Hash syntax
59
+ # Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
60
+ #
61
+ # @see Libnotify.new
62
+ def self.show(options={}, &block)
63
+ API.show(options, &block)
14
64
  end
15
65
 
16
66
  # Raw FFI bindings.
@@ -36,20 +86,25 @@ module Libnotify
36
86
  attr_reader :timeout
37
87
  attr_accessor :summary, :body, :icon_path, :urgency
38
88
 
39
- def initialize(options = {}, &block)
89
+ # Creates a notification object.
90
+ #
91
+ # @see Libnotify.new
92
+ def initialize(options={}, &block)
40
93
  set_defaults
41
94
  options.each { |key, value| send("#{key}=", value) if respond_to?(key) }
42
95
  yield(self) if block_given?
43
96
  end
44
97
 
45
98
  def set_defaults
46
- # TODO Empty strings give warnings
47
- self.summary = self.body = " "
99
+ self.summary = self.body = ' '
48
100
  self.urgency = :normal
49
101
  self.timeout = nil
50
102
  end
51
103
  private :set_defaults
52
104
 
105
+ # Shows a notification.
106
+ #
107
+ # @see Libnotify.show
53
108
  def show!
54
109
  notify_init(self.class.to_s) or raise "notify_init failed"
55
110
  notify = notify_notification_new(summary, body, icon_path, nil)
@@ -60,8 +115,8 @@ module Libnotify
60
115
  notify_uninit
61
116
  end
62
117
 
118
+ # @todo Simplify timeout=
63
119
  def timeout=(timeout)
64
- # TODO Simplify timeout=
65
120
  @timeout = case timeout
66
121
  when Float
67
122
  (timeout * 1000).to_i
@@ -78,8 +133,12 @@ module Libnotify
78
133
  end
79
134
  end
80
135
 
81
- def self.show(*args, &block)
82
- new(*args, &block).show!
136
+ # Creates and shows a notification. It's a shortcut for +Libnotify.new(options).show!+.
137
+ #
138
+ # @see Libnotify.show
139
+ # @see Libnotify.new
140
+ def self.show(options={}, &block)
141
+ new(options, &block).show!
83
142
  end
84
143
 
85
144
  end
data/libnotify.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{libnotify}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Suschlik"]
@@ -42,15 +42,18 @@ Gem::Specification.new do |s|
42
42
  s.add_runtime_dependency(%q<ffi>, [">= 0.6.2"])
43
43
  s.add_development_dependency(%q<riot>, [">= 0.1.12.pre"])
44
44
  s.add_development_dependency(%q<riot_notifier>, [">= 0.0.7"])
45
+ s.add_development_dependency(%q<yard>, [">= 0"])
45
46
  else
46
47
  s.add_dependency(%q<ffi>, [">= 0.6.2"])
47
48
  s.add_dependency(%q<riot>, [">= 0.1.12.pre"])
48
49
  s.add_dependency(%q<riot_notifier>, [">= 0.0.7"])
50
+ s.add_dependency(%q<yard>, [">= 0"])
49
51
  end
50
52
  else
51
53
  s.add_dependency(%q<ffi>, [">= 0.6.2"])
52
54
  s.add_dependency(%q<riot>, [">= 0.1.12.pre"])
53
55
  s.add_dependency(%q<riot_notifier>, [">= 0.0.7"])
56
+ s.add_dependency(%q<yard>, [">= 0"])
54
57
  end
55
58
  end
56
59
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libnotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Suschlik
@@ -42,6 +42,16 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  version: 0.0.7
44
44
  version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: yard
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
45
55
  description:
46
56
  email: peter-libnotify@suschlik.de
47
57
  executables: []