ionian 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/doc/Ionian/IO.html +489 -0
  3. data/doc/Ionian.html +99 -0
  4. data/doc/created.rid +3 -0
  5. data/doc/fonts/Lato-Light.ttf +0 -0
  6. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  7. data/doc/fonts/Lato-Regular.ttf +0 -0
  8. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  9. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  10. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  11. data/doc/fonts.css +167 -0
  12. data/doc/images/add.png +0 -0
  13. data/doc/images/arrow_up.png +0 -0
  14. data/doc/images/brick.png +0 -0
  15. data/doc/images/brick_link.png +0 -0
  16. data/doc/images/bug.png +0 -0
  17. data/doc/images/bullet_black.png +0 -0
  18. data/doc/images/bullet_toggle_minus.png +0 -0
  19. data/doc/images/bullet_toggle_plus.png +0 -0
  20. data/doc/images/date.png +0 -0
  21. data/doc/images/delete.png +0 -0
  22. data/doc/images/find.png +0 -0
  23. data/doc/images/loadingAnimation.gif +0 -0
  24. data/doc/images/macFFBgHack.png +0 -0
  25. data/doc/images/package.png +0 -0
  26. data/doc/images/page_green.png +0 -0
  27. data/doc/images/page_white_text.png +0 -0
  28. data/doc/images/page_white_width.png +0 -0
  29. data/doc/images/plugin.png +0 -0
  30. data/doc/images/ruby.png +0 -0
  31. data/doc/images/tag_blue.png +0 -0
  32. data/doc/images/tag_green.png +0 -0
  33. data/doc/images/transparent.png +0 -0
  34. data/doc/images/wrench.png +0 -0
  35. data/doc/images/wrench_orange.png +0 -0
  36. data/doc/images/zoom.png +0 -0
  37. data/doc/index.html +86 -0
  38. data/doc/js/darkfish.js +140 -0
  39. data/doc/js/jquery.js +18 -0
  40. data/doc/js/navigation.js +142 -0
  41. data/doc/js/search.js +102 -0
  42. data/doc/js/search_index.js +1 -0
  43. data/doc/js/searcher.js +228 -0
  44. data/doc/rdoc.css +574 -0
  45. data/doc/table_of_contents.html +90 -0
  46. data/lib/ionian/io.rb +110 -0
  47. data/lib/ionian.rb +1 -0
  48. data/license.txt +19 -0
  49. metadata +147 -0
data/lib/ionian/io.rb ADDED
@@ -0,0 +1,110 @@
1
+ module Ionian
2
+ # A mixin for IO objects that allows regular expression matching
3
+ # and convenient notification of data in the buffer.
4
+ #
5
+ # This module was designed to be EXTENDED by instantiated objects
6
+ # that implement the standard library IO class.
7
+ # my_socket.extend Ionian::IO
8
+ module IO
9
+ # Number of seconds to attempt an IO operation before timing out.
10
+ # See standard library IO::select.
11
+ attr_accessor :ionian_timeout
12
+
13
+ # Called automaticallly when the object is extended with #extend.
14
+ def self.extended(obj)
15
+ obj.initialize_ionian
16
+ end
17
+
18
+ # Initialize the Ionian instance variables.
19
+ # This is called automatically if #extend is called on an object.
20
+ def initialize_ionian
21
+ @ionian_listeners = []
22
+ @ionian_buf = ''
23
+ @ionian_expression = /(.*?)\n/
24
+ @ionian_timeout = 1
25
+ end
26
+
27
+ # Set the expression to match against the read buffer.
28
+ # Can be a regular expression specifying capture groups,
29
+ # or a string specifying the separator or line terminator
30
+ # sequence. It is possible to use named captures in a
31
+ # regex, which allows for convienient accessors like
32
+ # match[:parameter].
33
+ def match(expression)
34
+ @ionian_expression = expression
35
+ @ionian_expression = Regexp.new "(.*?)#{expression}" if expression.is_a? String
36
+ end
37
+
38
+ # Read matched data from the buffer.
39
+ # This method SHOULD NOT be used if #run_match is used.
40
+ #
41
+ # Passes matches to the block (do |match|). If there are multiple
42
+ # matches, the block is called multiple times.
43
+ #
44
+ # Returns an array of matches.
45
+ # Returns nil if no data was received within the timeout period.
46
+ #
47
+ # Junk data that could exist before a match in the buffer can
48
+ # be accessed with match.pre_match.
49
+ #
50
+ # Data at the end of the buffer that is not matched can be accessed
51
+ # in the last match with match.post_match. This data remains in the
52
+ # buffer for the next read_match cycle. This is helpful for protocols
53
+ # like RS232 that do not have packet boundries.
54
+ #
55
+ # kvargs:
56
+ # Timeout: Timeout in seconds IO::select will block.
57
+ def read_match(**kvargs, &block)
58
+ timeout = kvargs.fetch :timeout, @ionian_timeout
59
+
60
+ return nil unless IO.select [self], nil, nil, timeout
61
+ @ionian_buf << read_partial 0xFFFF
62
+
63
+ @matches = []
64
+
65
+ while @ionian_buf =~ @ionian_expression
66
+ @matches << $~ # Match data.
67
+ yield $~
68
+ end
69
+
70
+ @ionian_buf = $' # Leave post match data in the buffer.
71
+ @matches
72
+ end
73
+
74
+ # Start a thread that checks for data and notifies listeners.
75
+ # Passes kvargs to #read_match.
76
+ # This method SHOULD NOT be used if #read_match is used.
77
+ def run_match(**kvargs)
78
+ @match_listener ||= Thread.new do
79
+ while not closed? do
80
+ matches = read_match kvargs
81
+ @ionian_listeners.each {|listener| yield matches} if matches
82
+ end
83
+
84
+ @match_listener = nil
85
+ end
86
+ end
87
+
88
+ # Erase the data in Ionian's buffer.
89
+ def purge
90
+ @ionian_buf = ''
91
+ end
92
+
93
+ # Register a block to be called when #run_match receives matched data.
94
+ # Method callbacks can be registered with &object.method(:method).
95
+ # Returns a reference to the given block.
96
+ # block = ionian_socket.register_observer {...}
97
+ def register_observer(&block)
98
+ @ionian_listeners << block unless @ionian_listeners.include? block
99
+ block
100
+ end
101
+
102
+ # Unregister a block from being called when matched data is received.
103
+ def unregister_observer(&block)
104
+ @ionian_listeners.delete_if {|o| o == block}
105
+ block
106
+ end
107
+
108
+ end
109
+ end
110
+
data/lib/ionian.rb ADDED
@@ -0,0 +1 @@
1
+ require 'ionian/io'
data/license.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 Alex McLain
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ionian
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex McLain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
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: A mixin for IO objects that allows regular expression matching and convenient
70
+ notification of data in the buffer.
71
+ email: alex@alexmclain.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - doc/Ionian.html
77
+ - doc/Ionian/IO.html
78
+ - doc/created.rid
79
+ - doc/fonts.css
80
+ - doc/fonts/Lato-Light.ttf
81
+ - doc/fonts/Lato-LightItalic.ttf
82
+ - doc/fonts/Lato-Regular.ttf
83
+ - doc/fonts/Lato-RegularItalic.ttf
84
+ - doc/fonts/SourceCodePro-Bold.ttf
85
+ - doc/fonts/SourceCodePro-Regular.ttf
86
+ - doc/images/add.png
87
+ - doc/images/arrow_up.png
88
+ - doc/images/brick.png
89
+ - doc/images/brick_link.png
90
+ - doc/images/bug.png
91
+ - doc/images/bullet_black.png
92
+ - doc/images/bullet_toggle_minus.png
93
+ - doc/images/bullet_toggle_plus.png
94
+ - doc/images/date.png
95
+ - doc/images/delete.png
96
+ - doc/images/find.png
97
+ - doc/images/loadingAnimation.gif
98
+ - doc/images/macFFBgHack.png
99
+ - doc/images/package.png
100
+ - doc/images/page_green.png
101
+ - doc/images/page_white_text.png
102
+ - doc/images/page_white_width.png
103
+ - doc/images/plugin.png
104
+ - doc/images/ruby.png
105
+ - doc/images/tag_blue.png
106
+ - doc/images/tag_green.png
107
+ - doc/images/transparent.png
108
+ - doc/images/wrench.png
109
+ - doc/images/wrench_orange.png
110
+ - doc/images/zoom.png
111
+ - doc/index.html
112
+ - doc/js/darkfish.js
113
+ - doc/js/jquery.js
114
+ - doc/js/navigation.js
115
+ - doc/js/search.js
116
+ - doc/js/search_index.js
117
+ - doc/js/searcher.js
118
+ - doc/rdoc.css
119
+ - doc/table_of_contents.html
120
+ - lib/ionian.rb
121
+ - lib/ionian/io.rb
122
+ - license.txt
123
+ homepage: https://bitbucket.org/amclain/ionian
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.2.0.preview.1
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Regular expression matching and notification for IO.
147
+ test_files: []