Module: Utilities
- Included in:
- Worksheet
- Defined in:
- lib/surpass/utilities.rb
Instance Method Summary collapse
- #as_boolean(input) ⇒ Object
- #as_excel_date(date) ⇒ Object
- #as_numeric(input) ⇒ Object
- #binary_string_to_hex_array(binary_string) ⇒ Object
-
#hex(value) ⇒ Object
Mimic python’s “hex” function 0x00.
-
#hex_array_to_binary_string(array_of_hex_values) ⇒ Object
For ease of comparing with pyExcelerator output values python seems to automatically decode to hex values.
- #mock_unicode_string(s) ⇒ Object
- #pixels_to_points(pixels) ⇒ Object
- #pixels_to_twips(pixels) ⇒ Object
- #points_to_pixels(points) ⇒ Object
- #twips_to_pixels(twips) ⇒ Object
Instance Method Details
#as_boolean(input) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/surpass/utilities.rb', line 40 def as_boolean(input) case input when 1, true true when 0, false false else raise "Can't convert #{input} from excel boolean!" end end |
#as_excel_date(date) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/surpass/utilities.rb', line 28 def as_excel_date(date) date = DateTime.parse(date.strftime("%c")) if date.is_a?(Time) excel_date = (date - Date.civil(1899, 12, 31)).to_f excel_date += 1 if excel_date > 59 # Add a day for Excel's missing leap day in 1900 excel_date end |
#as_numeric(input) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/surpass/utilities.rb', line 51 def as_numeric(input) case input when true, 1 1 when false, 0 0 else raise "Can't convert #{input} to excel boolean!" end end |
#binary_string_to_hex_array(binary_string) ⇒ Object
8 9 10 |
# File 'lib/surpass/utilities.rb', line 8 def binary_string_to_hex_array(binary_string) binary_string.unpack("H*") end |
#hex(value) ⇒ Object
Mimic python’s “hex” function 0x00
63 64 65 |
# File 'lib/surpass/utilities.rb', line 63 def hex(value) "0x" + value.to_s(16) end |
#hex_array_to_binary_string(array_of_hex_values) ⇒ Object
For ease of comparing with pyExcelerator output values python seems to automatically decode to hex values
4 5 6 |
# File 'lib/surpass/utilities.rb', line 4 def hex_array_to_binary_string(array_of_hex_values) [array_of_hex_values.collect {|h| [sprintf("%02x", h)]}.join].pack('H*') end |
#mock_unicode_string(s) ⇒ Object
35 36 37 |
# File 'lib/surpass/utilities.rb', line 35 def mock_unicode_string(s) [s.length, 0].pack('vC') + s end |
#pixels_to_points(pixels) ⇒ Object
16 17 18 |
# File 'lib/surpass/utilities.rb', line 16 def pixels_to_points(pixels) pixels * (3.0 / 4) end |
#pixels_to_twips(pixels) ⇒ Object
24 25 26 |
# File 'lib/surpass/utilities.rb', line 24 def pixels_to_twips(pixels) pixels * 15.0 end |
#points_to_pixels(points) ⇒ Object
12 13 14 |
# File 'lib/surpass/utilities.rb', line 12 def points_to_pixels(points) points*(4.0/3) end |
#twips_to_pixels(twips) ⇒ Object
20 21 22 |
# File 'lib/surpass/utilities.rb', line 20 def twips_to_pixels(twips) twips / 15.0 end |