Skip to content

Commit

Permalink
fixnum -> integer for ruby 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
arirusso committed May 16, 2017
1 parent 37dad11 commit 33b1889
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions lib/nibbler/data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Nibbler

# Accepts various types of input and returns an array of hex digit chars
#
# Ideally this would output Fixnum objects. However, given that Ruby numerics 0x0 and 0x00 result in the same
# object (0 Fixnum), this would limit the parser to only working with bytes instead of both nibbles and bytes.
# Ideally this would output Integer objects. However, given that Ruby numerics 0x0 and 0x00 result in the same
# object (0 Integer), this would limit the parser to only working with bytes instead of both nibbles and bytes.
#
# For example, if the input were "5" then the processor would return an ambiguous 0x5
#
Expand All @@ -14,7 +14,7 @@ module DataProcessor
# Accepts various types of input and returns an array of hex digit chars
# Invalid input is disregarded
#
# @param [*String, *Fixnum] args
# @param [*String, *Integer] args
# @return [Array<String>] An array of hex string nibbles eg "6", "a"
def process(*args)
args.map { |arg| convert(arg) }.flatten.compact.map(&:upcase)
Expand All @@ -23,20 +23,20 @@ def process(*args)
private

# Convert a single value to hex chars
# @param [Array<Fixnum>, Array<String>, Fixnum, String] value
# @param [Array<Integer>, Array<String>, Integer, String] value
# @return [Array<String>]
def convert(value)
case value
when Array then value.map { |arr| process(*arr) }.reduce(:+)
when String then TypeConversion.hex_str_to_hex_chars(filter_string(value))
when Fixnum then TypeConversion.numeric_byte_to_hex_chars(filter_numeric(value))
when Integer then TypeConversion.numeric_byte_to_hex_chars(filter_numeric(value))
end
end

# Limit the given number to bytes usable in MIDI ie values (0..240)
# returns nil if the byte is outside of that range
# @param [Fixnum] num
# @return [Fixnum, nil]
# @param [Integer] num
# @return [Integer, nil]
def filter_numeric(num)
num if (0x00..0xFF).include?(num)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/nibbler/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(library)
end

# Process the given nibbles and add them to the buffer
# @param [Array<String, Fixnum>] nibbles
# @param [Array<String, Integer>] nibbles
# @return [Hash]
def process(nibbles)
report = {
Expand Down Expand Up @@ -57,7 +57,7 @@ def nibbles_to_message(fragment)
private

# Attempt to convert the given nibbles into a MIDI message
# @param [Array<Fixnum>] nibbles
# @param [Array<Integer>] nibbles
# @return [Hash, nil]
def compute_message(nibbles, fragment)
case nibbles[0]
Expand All @@ -80,7 +80,7 @@ def lookahead_using_running_status(fragment)
end

# Get the data in the buffer for the given pointer
# @param [Fixnum] pointer
# @param [Integer] pointer
# @return [Array<String>]
def get_fragment(pointer)
@buffer[pointer, (@buffer.length - pointer)]
Expand All @@ -89,7 +89,7 @@ def get_fragment(pointer)
# If the given fragment has at least the given number of nibbles, use it to build a hash that can be used
# to build a MIDI message
#
# @param [Fixnum] num_nibbles
# @param [Integer] num_nibbles
# @param [Array<String>] fragment
# @param [Hash] options
# @option options [String] :status_nibble_2
Expand Down
4 changes: 2 additions & 2 deletions lib/nibbler/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def log(parser_report, timestamp)
end

# @param [Array<Object>] messages The MIDI messages to log
# @return [Fixnum] The number of MIDI messages logged
# @return [Integer] The number of MIDI messages logged
def log_message(messages, options = {})
if @timestamps
messages_for_log = messages.count == 1 ? messages.first : messages
Expand All @@ -124,7 +124,7 @@ def log_message(messages, options = {})
# 1 message: the message
# >1 message: an array of messages
#
# @param [Fixnum] num The number of new messages to report
# @param [Integer] num The number of new messages to report
# @return [Array<Object>, Hash]
def get_output(num)
messages = @messages.last(num)
Expand Down
6 changes: 3 additions & 3 deletions lib/nibbler/type_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module TypeConversion
# Converts an array of hex nibble strings to numeric bytes
# eg ["9", "0", "5", "0", "4", "0"] => [0x90, 0x50, 0x40]
# @param [Array<String>] nibbles
# @return [Array<Fixnum>]
# @return [Array<Integer>]
def hex_chars_to_numeric_bytes(nibbles)
nibbles = nibbles.dup
# get rid of last nibble if there's an odd number
Expand Down Expand Up @@ -57,15 +57,15 @@ def numeric_bytes_to_numeric_nibbles(bytes)
end

# Converts a numeric byte to an array of hex nibble strings eg 0x90 => ["9", "0"]
# @param [Fixnum] num
# @param [Integer] num
# @return [Array<String>]
def numeric_byte_to_hex_chars(num)
nibbles = numeric_byte_to_numeric_nibbles(num)
nibbles.map { |n| n.to_s(16) }
end

# Converts a numeric byte to an array of numeric nibbles eg 0x90 => [0x9, 0x0]
# @param [Fixnum] num
# @param [Integer] num
# @return [Array<String>]
def numeric_byte_to_numeric_nibbles(num)
[((num & 0xF0) >> 4), (num & 0x0F)]
Expand Down

0 comments on commit 33b1889

Please sign in to comment.