Module: DmmUtil::FormatConvertors
- Included in:
- Fluke28xDriver
- Defined in:
- lib/dmm_util/format_convertors.rb
Instance Method Summary collapse
- #get_double(str, offset) ⇒ Object
- #get_s16(str, offset) ⇒ Object
- #get_time(str, offset) ⇒ Object
- #get_u16(str, offset) ⇒ Object
- #parse_time(t) ⇒ Object
- #quote_str(str) ⇒ Object
Instance Method Details
#get_double(str, offset) ⇒ Object
19 20 21 22 23 |
# File 'lib/dmm_util/format_convertors.rb', line 19 def get_double(str, offset) bytestr = str[offset, 8] endianstr = bytestr[0,4].reverse + bytestr[4,4].reverse endianstr.unpack("G")[0] end |
#get_s16(str, offset) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/dmm_util/format_convertors.rb', line 11 def get_s16(str, offset) val = get_u16(str, offset) unless (val & 0x8000) == 0 val = -(0x10000 - val) end val end |
#get_time(str, offset) ⇒ Object
25 26 27 |
# File 'lib/dmm_util/format_convertors.rb', line 25 def get_time(str, offset) parse_time(get_double(str, offset)) end |
#get_u16(str, offset) ⇒ Object
5 6 7 8 9 |
# File 'lib/dmm_util/format_convertors.rb', line 5 def get_u16(str, offset) lo_byte = str[offset] hi_byte = str[offset + 1] hi_byte * 0x100 + lo_byte end |
#parse_time(t) ⇒ Object
29 30 31 32 |
# File 'lib/dmm_util/format_convertors.rb', line 29 def parse_time(t) tz_offset = Time.now.utc_offset Time.at(t - tz_offset) end |
#quote_str(str) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dmm_util/format_convertors.rb', line 34 def quote_str(str) has_single = str.include?("'") has_double = str.include?('"') if has_single && !has_double "\"#{str}\"" else "'#{str.gsub(/'/, "''")}'" end end |