lib/origen/chips.rb in origen-0.60.7 vs lib/origen/chips.rb in origen-0.60.8
- old
+ new
@@ -35,17 +35,17 @@
part: nil,
chip: nil
}.update(options || {})
_chips
if s.nil?
- return show_chips(options)
+ show_chips(options)
elsif s.is_a? Hash
options.update(s)
- return show_chips(options)
+ show_chips(options)
else
options[:chip] = s
- return show_chips(options)
+ show_chips(options)
end
end
# Define and instantiate a Spec object
def chip(name, description, selector = {}, options = {}, &block)
@@ -59,10 +59,11 @@
power = selector[:power]
chip_holder = Chip.new(name, description, previous_parts, power, options)
if has_chip?(name, group: group, family: family, performance: performance, creating_chip: true)
fail "Chip already exists for chip: #{name}, group: #{group}, family: #{family} for object #{self}"
end
+
@_chips[group][family][performance][name] = chip_holder
end
# Returns Boolean based on whether the calling object has any defined specs
# If the mode option is selected then the search is narrowed
@@ -74,13 +75,13 @@
performance: nil,
chip: nil,
creating_chip: false
}.update(options)
if @_chips.nil? || @_chips == {}
- return false
+ false
else
- return !!show_chips(options)
+ !!show_chips(options)
end
end
# Check if the current IP has a spec
def has_chip?(s, options = {})
@@ -125,15 +126,15 @@
hash.filter(options[:type]).each do |type, note|
notes_found[id][type] = note
end
end
if notes_found.empty?
- return nil
+ nil
elsif notes_found.size == 1
notes_found.values.first.values.first
else
- return notes_found
+ notes_found
end
end
def docs(options = {})
options = {
@@ -182,10 +183,12 @@
@_designs = nil
end
private
+ # rubocop:disable Lint/DuplicateMethods
+
def _chips
# 4D hash with group, family, and performance
@_chips ||= Hash.new do |h, k|
h[k] = Hash.new do |hh, kk|
hh[kk] = Hash.new do |hhh, kkk|
@@ -213,25 +216,26 @@
def _designs
@_designs ||= Hash.new do |h, k|
h[k] = {}
end
end
+ # rubocop:enable Lint/DuplicateMethods
# Return a hash based on the filter provided
def filter_hash(hash, filter)
fail 'Hash argument is not a Hash!' unless hash.is_a? Hash
+
filtered_hash = {}
select_logic = case filter
when String then 'k[Regexp.new(filter)]'
when (Fixnum || Integer || Float || Numeric) then "k[Regexp.new('#{filter}')]"
when Regexp then 'k[filter]'
when Symbol then
'k == filter'
when NilClass then true # Return all specs if a filter is set to nil (i.e. user doesn't care about this filter)
else true
- end
- # rubocop:disable UnusedBlockArgument
+ end
filtered_hash = hash.select do |k, v|
[TrueClass, FalseClass].include?(select_logic.class) ? select_logic : eval(select_logic)
end
filtered_hash
end
@@ -266,16 +270,16 @@
options[:chips_to_be_shown] = chips_to_be_shown
Origen.log.debug "re-calling show_chips with options #{options}"
return show_chips(options)
end
Origen.log.debug "Returning no chips for options #{options}"
- return nil
+ nil
elsif chips_to_be_shown.size == 1
Origen.log.debug "returning one spec #{chips_to_be_shown.first.part_name}"
- return chips_to_be_shown.first
+ chips_to_be_shown.first
else
Origen.log.debug "returning an array of specs during initial search: #{chips_to_be_shown}"
- return chips_to_be_shown
+ chips_to_be_shown
end
end
end
end