Class: OLEStorageLite
- Inherits:
-
Object
- Object
- OLEStorageLite
- Defined in:
- lib/writeexcel/storage_lite.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary collapse
- PPS_TYPE_ROOT =
5- PPS_TYPE_DIR =
1- PPS_TYPE_FILE =
2- DATA_SIZE_SMALL =
0x1000- LONG_INT_SIZE =
4- PPS_SIZE =
0x80
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #asc2ucs(str) ⇒ Object
- #getNthPps(no, data) ⇒ Object
- #getPpsSearch(name, data, icase) ⇒ Object
- #getPpsTree(data) ⇒ Object
-
#initialize(file = nil) ⇒ OLEStorageLite
constructor
A new instance of OLEStorageLite.
-
#localDate2OLE(localtime) ⇒ Object
—————————————————————————— LocalDate2OLE().
-
#oleData2Local(oletime) ⇒ Object
—————————————————————————— OLEDate2Local().
- #ucs2asc(str) ⇒ Object
Constructor Details
#initialize(file = nil) ⇒ OLEStorageLite
Returns a new instance of OLEStorageLite.
14 15 16 |
# File 'lib/writeexcel/storage_lite.rb', line 14 def initialize(file = nil) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
12 13 14 |
# File 'lib/writeexcel/storage_lite.rb', line 12 def file @file end |
Instance Method Details
#asc2ucs(str) ⇒ Object
343 344 345 |
# File 'lib/writeexcel/storage_lite.rb', line 343 def asc2ucs(str) str.split(//).join("\0") + "\0" end |
#getNthPps(no, data) ⇒ Object
28 29 30 31 |
# File 'lib/writeexcel/storage_lite.rb', line 28 def getNthPps(no, data) info = _initParse(file) info ? _getNthPps(no, info, data) : nil end |
#getPpsSearch(name, data, icase) ⇒ Object
23 24 25 26 |
# File 'lib/writeexcel/storage_lite.rb', line 23 def getPpsSearch(name, data, icase) info = _initParse(file) info ? _getPpsSearch(0, info, name, data, icase) : nil end |
#getPpsTree(data) ⇒ Object
18 19 20 21 |
# File 'lib/writeexcel/storage_lite.rb', line 18 def getPpsTree(data) info = _initParse(file) info ? _getPpsTree(0, info, data) : nil end |
#localDate2OLE(localtime) ⇒ Object
LocalDate2OLE()
Convert from a a localtime array to a Window FILETIME structure. FILETIME is a 64-bit value representing the number of 100-nanosecond intervals since January 1 1601.
We first convert the localtime (actually gmtime) to seconds and then add the difference between the 1601 epoch and the 1970 Unix epoch. We convert that to 100 nanosecond units, divide it into high and low longs and return it as a packed 64bit structure.
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/writeexcel/storage_lite.rb', line 400 def localDate2OLE(localtime) return "\x00" * 8 unless localtime # Convert from localtime (actually gmtime) to seconds. args = localtime.reverse args[0] += 1900 # year args[1] += 1 # month time = Time.gm(*args) # Add the number of seconds between the 1601 and 1970 epochs. time = time.to_i + 11644473600 # The FILETIME seconds are in units of 100 nanoseconds. nanoseconds = time * 10000000 # Pack the total nanoseconds into 64 bits... hi, lo = nanoseconds.divmod 1 << 32 [lo, hi].pack("VV") # oletime end |
#oleData2Local(oletime) ⇒ Object
OLEDate2Local()
Convert from a Window FILETIME structure to a localtime array. FILETIME is a 64-bit value representing the number of 100-nanosecond intervals since January 1 1601.
We first convert the FILETIME to seconds and then subtract the difference between the 1601 epoch and the 1970 Unix epoch.
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/writeexcel/storage_lite.rb', line 362 def oleData2Local(oletime) # Unpack the FILETIME into high and low longs. lo, hi = oletime.unpack('V2') # Convert the longs to a double. nanoseconds = hi * 2 ** 32 + lo # Convert the 100 nanosecond units into seconds. time = nanoseconds / 1e7 # Subtract the number of seconds between the 1601 and 1970 epochs. time -= 11644473600 # Convert to a localtime (actually gmtime) structure. if time >= 1 ltime = Time.at(time).getgm.to_a[0, 9] ltime[4] -= 1 # month ltime[5] -= 1900 # year ltime[7] -= 1 # past from 1, Jan ltime[8] = ltime[8] ? 1 : 0 ltime else [] end end |
#ucs2asc(str) ⇒ Object
347 348 349 350 |
# File 'lib/writeexcel/storage_lite.rb', line 347 def ucs2asc(str) ary = str.unpack('v*').map { |s| [s].pack('c')} ary.join('') end |