Skip to content

Commit

Permalink
Rubocop again...
Browse files Browse the repository at this point in the history
  • Loading branch information
MahtraDR authored Dec 17, 2024
1 parent 1671b69 commit dbe8ddc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions rummage.lic
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Rummage

def get_container_contents(container)
full_contents = Lich::Util.issue_command("rummage #{container}", /^You rummage .* but there is nothing in there\.$|^You rummage .* and see (.*)\./, quiet: true)

rummage_line = full_contents.find { |line| line.start_with?('You rummage') }

if rummage_line =~ /but there is nothing in there/
container_name = rummage_line.match(/^You rummage (.*?) but/)[1]
return [container_name, []]
Expand All @@ -24,14 +24,14 @@ class Rummage
return [container_name, DRC.list_to_array(contents)]
end
end

def sort_items(items)
sorted = {}
items.each do |item|
clean_item = item.sub(/^\s*?\b(?:a|an|some|and|the)\b\s/, '').chomp('.')
noun = DRC.get_noun(clean_item)
type = get_item_type(clean_item, noun)

if sorted[type]
if sorted[type][clean_item]
sorted[type][clean_item][:qty] += 1
Expand All @@ -48,28 +48,28 @@ class Rummage
def get_item_type(item, noun)
item_data = get_data('sorting').to_h.merge(get_data('items').to_h)
category = 'Other'

item_data.each do |key, value|
if noun =~ /#{value.join('$|').concat('$')}/i || item =~ /(?:#{value.join('$|').concat('$')})/i
category = key.to_s.sub(/_nouns|_types/, '').capitalize
break
end
end

category
end

def display_table(sorted_items, container_name)
table = Terminal::Table.new do |t|
t.title = "Contents of #{container_name.strip}"
t.style = { border_x: "-", border_i: "+", border_y: "|" }

if sorted_items.empty?
t << [{ value: "This container is empty", alignment: :center, colspan: 2 }]
else
t.headings = ['Item', 'Qty.']
sorted_types = sorted_items.keys.sort_by { |type| type == "Other" ? [1, type] : [0, type] }

sorted_types.each do |type|
items = sorted_items[type]
t << :separator
Expand Down

0 comments on commit dbe8ddc

Please sign in to comment.