Module: Aura::P
- Extended by:
- Aura
- Defined in:
- lib/aura.rb
Constant Summary
Constants included from Aura
Class Method Summary collapse
- .cite(ship) ⇒ Object
-
.clan(who) ⇒ Object
Find whether the given @p-encoded string is a galaxy, star, planet, moon, or comet.
- .de_sig(ship) ⇒ Object
-
.hex2patp(hex) ⇒ Object
Convert a hex-encoded string to a @p-encoded string.
-
.patp(arg) ⇒ Object
Convert a number into a @p-encoded string.
-
.patp2dec(name) ⇒ Object
Convert a @p-encoded string to an integer.
-
.patp2hex(name) ⇒ Object
Convert a @p-encoded string to a hex-encoded string.
- .pre_sig(ship) ⇒ Object
-
.sein(name) ⇒ Object
Find the parent of the given @p-encoded string.
- .syl2bin(idx) ⇒ Object
-
.valid_patp?(str) ⇒ Boolean
Validate a @p-encoded string.
Methods included from Aura
bex, end_bits, met, patp2syls, rsh, valid_pat?, version
Class Method Details
.cite(ship) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/aura.rb', line 208 def self.cite(ship) return nil if ship.nil? || ship.empty? patp = de_sig(ship) case patp.length when 56 # comet pre_sig("#{patp[0..5]}_#{patp[50..55]}") when 27 # moon pre_sig("#{patp[14..19]}^#{patp[21..26]}") else pre_sig(patp) end end |
.clan(who) ⇒ Object
Find whether the given @p-encoded string is a galaxy, star, planet, moon, or comet.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/aura.rb', line 127 def self.clan(who) begin name = patp2dec(who) rescue ArgumentError raise "clan: not a valid @p" end wid = met(3, name) case wid when (0..1) then "galaxy" when 2 then "star" when (3..4) then "planet" when (5..8) then "moon" else "comet" end end |
.de_sig(ship) ⇒ Object
202 203 204 205 206 |
# File 'lib/aura.rb', line 202 def self.de_sig(ship) return "" if ship.nil? || ship.empty? ship.gsub("~", "") end |
.hex2patp(hex) ⇒ Object
Convert a hex-encoded string to a @p-encoded string.
98 99 100 101 102 |
# File 'lib/aura.rb', line 98 def self.hex2patp(hex) raise ArgumentError, "hex2patp: null input" if hex.nil? patp(hex.delete_prefix("0x").to_i(16)) end |
.patp(arg) ⇒ Object
Convert a number into a @p-encoded string.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/aura.rb', line 169 def self.patp(arg) raise ArgumentError, "patp: null input" if arg.nil? n = arg.to_i # Assuming arg can be converted to an integer directly sxz = Ob.fein(n) dyy = met(4, sxz) loop_fn = lambda do |tsxz, timp, trep| log = end_bits(4, 1, tsxz) pre = PREFIXES[rsh(3, 1, log)] suf = SUFFIXES[end_bits(3, 1, log)] etc = if (timp % 4).zero? timp.zero? ? "" : "--" else "-" end res = pre + suf + etc + trep timp == dyy ? trep : loop_fn.call(rsh(4, 1, tsxz), timp + 1, res) end dyx = met(3, sxz) "~#{dyx <= 1 ? SUFFIXES[sxz] : loop_fn.call(sxz, 0, "")}" end |
.patp2dec(name) ⇒ Object
Convert a @p-encoded string to an integer.
119 120 121 122 123 |
# File 'lib/aura.rb', line 119 def self.patp2dec(name) patp2hex(name).to_i(16) rescue ArgumentError raise "patp2dec: not a valid @p" end |
.patp2hex(name) ⇒ Object
Convert a @p-encoded string to a hex-encoded string.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/aura.rb', line 105 def self.patp2hex(name) raise ArgumentError, "patp2hex: not a valid @p" unless valid_pat?(name) syls = patp2syls(name) addr = syls.each_with_index.inject("") do |acc, (syl, idx)| idx.odd? || syls.length == 1 ? acc + syl2bin(SUFFIXES.index(syl)) : acc + syl2bin(PREFIXES.index(syl)) end bn = addr.to_i(2) hex = Ob.fynd(bn).to_s(16) hex.length.odd? ? hex.rjust(hex.length + 1, "0") : hex end |
.pre_sig(ship) ⇒ Object
196 197 198 199 200 |
# File 'lib/aura.rb', line 196 def self.pre_sig(ship) return "" if ship.nil? || ship.empty? ship.strip.start_with?("~") ? ship.strip : "~#{ship.strip}" end |
.sein(name) ⇒ Object
Find the parent of the given @p-encoded string.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/aura.rb', line 145 def self.sein(name) begin who = patp2dec(name) mir = clan(name) rescue ArgumentError raise "sein: not a valid @p" end res = case mir when "galaxy" then who when "star" then end_bits(3, 1, who) when "planet" then end_bits(4, 1, who) when "moon" then end_bits(5, 1, who) else 0 end patp(res) end |
.syl2bin(idx) ⇒ Object
222 223 224 |
# File 'lib/aura.rb', line 222 def self.syl2bin(idx) idx.to_s(2).rjust(8, "0") end |
.valid_patp?(str) ⇒ Boolean
Validate a @p-encoded string.
164 165 166 |
# File 'lib/aura.rb', line 164 def self.valid_patp?(str) valid_pat?(str) && str == patp(patp2dec(str)) end |