QSID 0.4 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/QSID.rb +195 -140
- metadata +1 -1
data/lib/QSID.rb
CHANGED
@@ -1,149 +1,204 @@
|
|
1
1
|
=begin
|
2
|
-
/***
|
3
|
-
* QSID
|
4
|
-
* @author - Skylar Schipper
|
5
|
-
* @copyright - (2011 - 2012) (c) QuietSight Inc
|
6
|
-
* (All rights reserved)
|
7
|
-
*
|
8
|
-
* QSID.rb
|
9
|
-
* 10/09/2011
|
10
|
-
*
|
11
|
-
/////////////////////////////////////////////////////////
|
12
|
-
|
13
|
-
Redistribution and use in source and binary forms, with or without
|
14
|
-
modification, are permitted provided that the following conditions are met:
|
15
|
-
*Redistributions of source code must retain the above copyright
|
16
|
-
notice, this list of conditions and the following disclaimer.
|
17
|
-
*Redistributions in binary form must reproduce the above copyright
|
18
|
-
notice, this list of conditions and the following disclaimer in the
|
19
|
-
documentation and/or other materials provided with the distribution.
|
20
|
-
*Neither the name of Skylar Schipper nor the names of any contributors may
|
21
|
-
be used to endorse or promote products derived from this software without
|
22
|
-
specific prior written permission.
|
23
|
-
|
24
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
25
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
26
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
27
|
-
DISCLAIMED. IN NO EVENT SHALL SKYLAR SCHIPPER OR QUIET SIGHT INC BE LIABLE FOR ANY
|
28
|
-
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
29
|
-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
30
|
-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
31
|
-
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
32
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
33
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
-
|
35
|
-
/////////////////////////////////////////////////////////
|
36
|
-
*
|
37
|
-
*
|
38
|
-
*
|
39
|
-
*
|
40
|
-
*
|
41
|
-
*
|
42
|
-
***/
|
43
|
-
=end
|
44
|
-
|
45
|
-
class QSID
|
46
|
-
|
47
|
-
## This is what is called to create a new ID
|
48
|
-
def self.newID
|
49
|
-
self.id = self._makeID
|
50
|
-
return self.id
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
# Timestamp
|
55
|
-
def self.timestamp
|
56
|
-
@timestamp
|
57
|
-
end
|
58
|
-
def self.timestamp=(time)
|
59
|
-
@timestamp = time
|
60
|
-
end
|
61
|
-
# Year
|
62
|
-
def self.year
|
63
|
-
@year
|
64
|
-
end
|
65
|
-
def self.year=(year)
|
66
|
-
@year = year
|
67
|
-
end
|
68
|
-
# Month
|
69
|
-
def self.month
|
70
|
-
@month
|
71
|
-
end
|
72
|
-
def self.month=(month)
|
73
|
-
if month < 10
|
74
|
-
month = "0#{month}"
|
75
|
-
end
|
76
|
-
@month = month
|
77
|
-
end
|
78
|
-
# Day
|
79
|
-
def self.day
|
80
|
-
@day
|
81
|
-
end
|
82
|
-
def self.day=(day)
|
83
|
-
if day < 10
|
84
|
-
day = "0#{day}"
|
85
|
-
end
|
86
|
-
@day = day
|
87
|
-
end
|
88
|
-
# Metadata
|
89
|
-
def self.meta
|
90
|
-
@meta
|
91
|
-
end
|
92
|
-
def self.meta=(meta)
|
93
|
-
@meta = meta
|
94
|
-
end
|
95
|
-
# rand 1
|
96
|
-
def self.rand1
|
97
|
-
@rand1
|
98
|
-
end
|
99
|
-
def self.rand1=(r1)
|
100
|
-
@rand1 = r1
|
101
|
-
end
|
102
|
-
# rand 2
|
103
|
-
def self.rand2
|
104
|
-
@rand2
|
105
|
-
end
|
106
|
-
def self.rand2=(r2)
|
107
|
-
@rand2 = r2
|
108
|
-
end
|
2
|
+
/***
|
3
|
+
* QSID
|
4
|
+
* @author - Skylar Schipper
|
5
|
+
* @copyright - (2011 - 2012) (c) QuietSight Inc
|
6
|
+
* (All rights reserved)
|
7
|
+
*
|
8
|
+
* QSID.rb
|
9
|
+
* 10/09/2011
|
10
|
+
*
|
11
|
+
/////////////////////////////////////////////////////////
|
109
12
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
13
|
+
Redistribution and use in source and binary forms, with or without
|
14
|
+
modification, are permitted provided that the following conditions are met:
|
15
|
+
*Redistributions of source code must retain the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer.
|
17
|
+
*Redistributions in binary form must reproduce the above copyright
|
18
|
+
notice, this list of conditions and the following disclaimer in the
|
19
|
+
documentation and/or other materials provided with the distribution.
|
20
|
+
*Neither the name of Skylar Schipper nor the names of any contributors may
|
21
|
+
be used to endorse or promote products derived from this software without
|
22
|
+
specific prior written permission.
|
116
23
|
|
24
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
25
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
26
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
27
|
+
DISCLAIMED. IN NO EVENT SHALL SKYLAR SCHIPPER OR QUIET SIGHT INC BE LIABLE FOR ANY
|
28
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
29
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
30
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
31
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
32
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
33
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
117
34
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
id = id + "#{self.day}"
|
131
|
-
id = id + "#{self.timestamp}"
|
132
|
-
id = id + "#{self.meta}"
|
133
|
-
id = id + "#{self.rand1}"
|
134
|
-
id = id + "#{self.rand2}"
|
135
|
-
|
136
|
-
return id
|
35
|
+
/////////////////////////////////////////////////////////
|
36
|
+
*
|
37
|
+
*
|
38
|
+
*
|
39
|
+
*
|
40
|
+
*
|
41
|
+
*
|
42
|
+
***/
|
43
|
+
=end
|
44
|
+
module QSID
|
45
|
+
def self.newID
|
46
|
+
self::Helper.makeID
|
137
47
|
end
|
138
48
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
49
|
+
###
|
50
|
+
#
|
51
|
+
# => Parser
|
52
|
+
#
|
53
|
+
###
|
54
|
+
class Parser
|
55
|
+
@id = nil
|
56
|
+
def id
|
57
|
+
@id
|
58
|
+
end
|
59
|
+
def id=(id)
|
60
|
+
@id = id
|
61
|
+
end
|
62
|
+
|
63
|
+
def initialize(id)
|
64
|
+
@id = id
|
65
|
+
end
|
66
|
+
|
67
|
+
# => Year
|
68
|
+
def year
|
69
|
+
@id[0..1]
|
70
|
+
end
|
71
|
+
# => Month
|
72
|
+
def month
|
73
|
+
@id[2..3]
|
74
|
+
end
|
75
|
+
# => Day
|
76
|
+
def day
|
77
|
+
@id[4..5]
|
78
|
+
end
|
79
|
+
# => Timestamp
|
80
|
+
def timestamp
|
81
|
+
@id[6..15]
|
82
|
+
end
|
83
|
+
# => Metadata
|
84
|
+
def metadata
|
85
|
+
@id[16..21]
|
86
|
+
end
|
87
|
+
def meta(m)
|
88
|
+
meta = self.metadata
|
89
|
+
if m == 0
|
90
|
+
meta[0..0]
|
91
|
+
elsif m == 1
|
92
|
+
meta[1..1]
|
93
|
+
elsif m == 2
|
94
|
+
meta[2..2]
|
95
|
+
elsif m == 3
|
96
|
+
meta[3..3]
|
97
|
+
elsif m == 4
|
98
|
+
meta[4..4]
|
99
|
+
elsif m == 5
|
100
|
+
meta[5..5]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# => Rand1
|
105
|
+
def rand1
|
106
|
+
@id[22..27]
|
107
|
+
end
|
108
|
+
# => Rand2
|
109
|
+
def rand2
|
110
|
+
@id[28..32]
|
111
|
+
end
|
112
|
+
|
113
|
+
# => Is Valid
|
114
|
+
def valid?
|
115
|
+
meta = self.metadata
|
116
|
+
id = meta[0..0].to_i
|
117
|
+
if id != 1
|
118
|
+
false
|
119
|
+
else
|
120
|
+
true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def created_by
|
125
|
+
meta = self.metadata
|
126
|
+
cb = meta[1..1].to_i
|
127
|
+
if cb == 1
|
128
|
+
"PHP"
|
129
|
+
elsif cb == 2
|
130
|
+
"Objective-C"
|
131
|
+
elsif cb == 3
|
132
|
+
"Ruby"
|
133
|
+
elsif cb == 4
|
134
|
+
"Java"
|
135
|
+
elsif cb == 5
|
136
|
+
"Javascript"
|
137
|
+
elsif cb == 6
|
138
|
+
"C"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
145
142
|
end
|
146
|
-
|
147
|
-
|
143
|
+
###
|
144
|
+
#
|
145
|
+
# => Helper Class
|
146
|
+
#
|
147
|
+
###
|
148
|
+
class Helper
|
149
|
+
def self.makeID
|
150
|
+
time = Time.now
|
151
|
+
id = ''
|
152
|
+
id = id + "#{self.year(time.year)}"
|
153
|
+
id = id + "#{self.month(time.month)}"
|
154
|
+
id = id + "#{self.day(time.day)}"
|
155
|
+
id = id + "#{time.to_i}"
|
156
|
+
id = id + "#{self.__genMeta}"
|
157
|
+
id = id + "#{self.__genRand1}"
|
158
|
+
id = id + "#{self.__genRand2}"
|
159
|
+
id
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
###
|
164
|
+
## => Begin Private Methods
|
165
|
+
###
|
166
|
+
private
|
167
|
+
###
|
168
|
+
## => Year
|
169
|
+
###
|
170
|
+
def self.year(year)
|
171
|
+
year.to_i - 2000
|
172
|
+
end
|
173
|
+
###
|
174
|
+
## => Months
|
175
|
+
###
|
176
|
+
def self.month(month)
|
177
|
+
if month < 10
|
178
|
+
month = "0#{month}"
|
179
|
+
end
|
180
|
+
month
|
181
|
+
end
|
182
|
+
|
183
|
+
###
|
184
|
+
## => Day
|
185
|
+
###
|
186
|
+
def self.day(day)
|
187
|
+
if day < 10
|
188
|
+
day = "0#{day}"
|
189
|
+
end
|
190
|
+
day
|
191
|
+
end
|
192
|
+
|
193
|
+
def self.__genMeta
|
194
|
+
130000
|
195
|
+
end
|
196
|
+
def self.__genRand1
|
197
|
+
rand(999999-100000)
|
198
|
+
end
|
199
|
+
def self.__genRand2
|
200
|
+
rand(9999-1000)
|
201
|
+
end
|
202
|
+
|
148
203
|
end
|
149
204
|
end
|