From 5a6f72c6ecfce0b686cadad22157aa634361be2c Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 9 Nov 2010 16:47:25 -0600 Subject: [PATCH] better formatting --- bin/run_hourly.sh | 1 + lib/Lacuna/DB/Result/Mission.pm | 12 ++++++------ lib/Lacuna/Util.pm | 8 +++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/run_hourly.sh b/bin/run_hourly.sh index 94adbff2..1adc93ec 100755 --- a/bin/run_hourly.sh +++ b/bin/run_hourly.sh @@ -7,4 +7,5 @@ perl summarize_server.pl perl summarize_economy.pl perl generate_news_feeds.pl perl tick_spies.pl +perl add_missions.pl perl saben/hourly_update.pl diff --git a/lib/Lacuna/DB/Result/Mission.pm b/lib/Lacuna/DB/Result/Mission.pm index 158a88f2..dc45d8dc 100644 --- a/lib/Lacuna/DB/Result/Mission.pm +++ b/lib/Lacuna/DB/Result/Mission.pm @@ -3,7 +3,7 @@ package Lacuna::DB::Result::Mission; use Moose; no warnings qw(uninitialized); extends 'Lacuna::DB::Result'; -use Lacuna::Util qw(format_date); +use Lacuna::Util qw(format_date commify); use UUID::Tiny ':std'; use Config::JSON; use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES); @@ -247,12 +247,12 @@ sub format_items { my @items; # essentia - push @items, sprintf('Essentia: %d essentia.', $items->{essentia}) if ($items->{essentia}); + push @items, sprintf('Essentia: %s essentia.', commify($items->{essentia})) if ($items->{essentia}); # resources my @resources; foreach my $resource (keys %{ $items->{resources}}) { - push @resources, sprintf('%d %s', $items->{resources}{$resource}, $resource); + push @resources, sprintf('%s %s', commify($items->{resources}{$resource}), $resource); } push @items, $self->format_list('Resources',@resources); @@ -264,8 +264,8 @@ sub format_items { my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships'); foreach my $stats (@{ $items->{ships}}) { my $ship = $ships->new({type=>$stats->{type}}); - my $pattern = $is_objective ? '%s (speed >= %d, stealth >= %d, hold size >= %d)' : '%s (speed: %d, stealth: %d, hold size: %d)' ; - push @ships, sprintf($pattern, $ship->type_formatted, $stats->{speed}, $stats->{stealth}, $stats->{hold_size}); + my $pattern = $is_objective ? '%s (speed >= %s, stealth >= %s, hold size >= %s)' : '%s (speed: %s, stealth: %s, hold size: %s)' ; + push @ships, sprintf($pattern, $ship->type_formatted, commify($stats->{speed}), commify($stats->{stealth}), commify($stats->{hold_size})); } push @items, $self->format_list('Ships',@ships); @@ -292,7 +292,7 @@ sub format_list { } elsif (scalar(@list) > 1) { my $last = pop @list; - push @out, sprintf($label.': %s and %s', join(',', @list), $last); + push @out, sprintf($label.': %s and %s', join('; ', @list), $last); } return @out; } diff --git a/lib/Lacuna/Util.pm b/lib/Lacuna/Util.pm index d75d6bf9..4d3f34b4 100644 --- a/lib/Lacuna/Util.pm +++ b/lib/Lacuna/Util.pm @@ -6,7 +6,7 @@ use DateTime::Format::Duration; use DateTime::Format::Strptime; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(randint format_date random_element); +@EXPORT_OK = qw(randint format_date random_element commify); sub format_date { @@ -29,4 +29,10 @@ sub random_element { return $list->[randint(0, scalar(@{$list} -1 ))]; } +sub commify { + my $text = reverse $_[0]; + $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; + return scalar reverse $text; +} + 1; -- 2.51.2