subtype 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/subtype.rb +155 -0
  2. metadata +64 -0
data/lib/subtype.rb ADDED
@@ -0,0 +1,155 @@
1
+ #--
2
+ # Copyleft shura. [ shura1991@gmail.com ]
3
+ #
4
+ # This file is part of subtype.
5
+ #
6
+ # subtype is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # subtype is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with subtype. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ class ::Subtle::Sublet
21
+ def use(str)
22
+ self.instance_eval(str) if str.is_a?(String)
23
+ end
24
+ end
25
+
26
+ class ::Symbol
27
+ def long?
28
+ self == :long
29
+ end
30
+
31
+ def short?
32
+ self == :short
33
+ end
34
+ end
35
+
36
+ module SubType
37
+ class RotationType
38
+ attr_accessor :pre, :post
39
+ def initialize(phrase = '', max = 20, pre = '', post = '')
40
+ @max = max || 20
41
+ self.pre = pre || ''
42
+ self.post = post || ''
43
+ self.phrase = phrase
44
+ end
45
+
46
+ def update(phrase)
47
+ self.phrase = phrase unless phrase.is_a?(String) and
48
+ @phrase.strip == phrase.strip
49
+ end
50
+
51
+ def next
52
+ @rotation.rotate! if @phrase.size > @max
53
+ @rotation.join[0, @max]
54
+ end
55
+
56
+ protected
57
+ def phrase=(phrase = '')
58
+ @phrase = phrase || ''
59
+ @rotation = phrase.split(//)
60
+ @rotation.unshift(' ') if @phrase.size > @max
61
+ end
62
+ end
63
+
64
+ Rotate = <<-EOF
65
+ alias __set_data__ data=
66
+ alias __get_data__ data
67
+ alias __on__ on
68
+
69
+ self.rotation = SubType::RotationType.new('', self.config[:length])
70
+ self.thread = Thread.start(self) {|s|
71
+ loop {
72
+ s.__set_data__(s.data.pre + s.data.next + s.data.post)
73
+ sleep 0.1
74
+ }
75
+ }
76
+
77
+ def data=(str)
78
+ self.rotation.update(str)
79
+ str
80
+ end
81
+
82
+ def data
83
+ self.rotation
84
+ end
85
+
86
+ def on(meth, &blk)
87
+ case meth
88
+ when :unload
89
+ __on__(meth) {|s|
90
+ blk.call(s)
91
+ s.thread.kill
92
+ }
93
+ else
94
+ __on__(meth, &blk)
95
+ end
96
+ end
97
+ EOF
98
+
99
+ Expand = <<-EOF
100
+ helper do
101
+ def __refresh
102
+ begin
103
+ self.data = self.respond_to?(:refresh) ? self.refresh : ''
104
+ rescue
105
+ self.data = 'ERROR'
106
+ end
107
+ end
108
+ end
109
+
110
+ on :run do |s|
111
+ s.type = s.type ? s.type : :short
112
+ s.__refresh
113
+ end
114
+
115
+ on :mouse_over do |s|
116
+ s.type = :long
117
+ s.__refresh
118
+ end
119
+
120
+ on :mouse_out do |s|
121
+ s.type = :short
122
+ s.__refresh
123
+ end
124
+
125
+ alias __on__ on
126
+
127
+ def on(meth, &blk)
128
+ case meth
129
+ when :run
130
+ __on__(meth) {|s|
131
+ s.type = s.type ? s.type : :short
132
+ blk.call(s)
133
+ s.__refresh
134
+ }
135
+ when :mouse_over
136
+ __on__(meth) {|s|
137
+ blk.call(s)
138
+ s.type = :long
139
+ s.__refresh
140
+ }
141
+ when :mouse_out
142
+ __on__(meth) {|s|
143
+ blk.call(s)
144
+ s.type = :short
145
+ s.__refresh
146
+ }
147
+ else
148
+ __on__(meth) {|*args|
149
+ blk.call(*args)
150
+ args.last.__refresh
151
+ }
152
+ end
153
+ end
154
+ EOF
155
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subtype
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - shura
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-04-20 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Gem including some helpers to easily make your sublet
22
+ email: shura1991@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/subtype.rb
31
+ has_rdoc: true
32
+ homepage: http://github.com/shurizzle/subtype
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.7
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Gem including some helpers to easily make your sublet
63
+ test_files: []
64
+