Module: LC3Spec::Helpers
- Included in:
- LC3, Expectations, Test
- Defined in:
- lib/lc3spec/helpers.rb
Instance Method Summary collapse
- #is_absolute_path?(path) ⇒ Boolean
- #normalize_to_i(number) ⇒ Object
- #normalize_to_s(number) ⇒ Object
Instance Method Details
#is_absolute_path?(path) ⇒ Boolean
43 44 45 |
# File 'lib/lc3spec/helpers.rb', line 43 def is_absolute_path?(path) Pathname.new(path).absolute? end |
#normalize_to_i(number) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lc3spec/helpers.rb', line 20 def normalize_to_i(number) case number when String if number =~ /^(?:x|0x|X|0X)?([0-9A-Fa-f]{1,4})$/ num_part = $1 if num_part[0].to_i(16) > 7 num_part = num_part.rjust(4, 'F') else num_part = num_part.rjust(4, '0') end [num_part].pack('H*').unpack('s>*').first else raise ArgumentError, "Unable to normalize number: #{number}" end when Fixnum number else raise ArgumentError, "Expecting String or Fixnum, got #{number.class}" end end |
#normalize_to_s(number) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lc3spec/helpers.rb', line 5 def normalize_to_s(number) case number when String if number =~ /^(?:x|0x|X|0X)?([0-9A-Fa-f]{1,4})$/ "x#{$1.rjust(4, '0').upcase}" else raise ArgumentError, "Unable to normalize number: #{number}" end when Fixnum "x#{([number].pack('s>*')).unpack('H*').first.upcase}" else raise ArgumentError, "Expecting String or Fixnum, got #{number.class}" end end |