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.
25 26 27 |
# File 'lib/writeexcel/storage_lite.rb', line 25 def initialize(file = nil) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
23 24 25 |
# File 'lib/writeexcel/storage_lite.rb', line 23 def file @file end |
Instance Method Details
#asc2ucs(str) ⇒ Object
351 352 353 |
# File 'lib/writeexcel/storage_lite.rb', line 351 def asc2ucs(str) str.split(//).join("\0") + "\0" end |
#getNthPps(no, data) ⇒ Object
39 40 41 42 |
# File 'lib/writeexcel/storage_lite.rb', line 39 def getNthPps(no, data) info = _initParse(file) info ? _getNthPps(no, info, data) : nil end |
#getPpsSearch(name, data, icase) ⇒ Object
34 35 36 37 |
# File 'lib/writeexcel/storage_lite.rb', line 34 def getPpsSearch(name, data, icase) info = _initParse(file) info ? _getPpsSearch(0, info, name, data, icase) : nil end |
#getPpsTree(data) ⇒ Object
29 30 31 32 |
# File 'lib/writeexcel/storage_lite.rb', line 29 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.
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/writeexcel/storage_lite.rb', line 408 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.
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/writeexcel/storage_lite.rb', line 370 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
355 356 357 358 |
# File 'lib/writeexcel/storage_lite.rb', line 355 def ucs2asc(str) ary = str.unpack('v*').map { |s| [s].pack('c')} ary.join('') end |