File Coverage

blib/lib/WWW/ARDB/Result/ArcEnemy.pm
Criterion Covered Total %
statement 21 23 91.3
branch 4 8 50.0
condition 4 4 100.0
subroutine 7 7 100.0
pod 4 4 100.0
total 40 46 86.9


line stmt bran cond sub pod time code
1             package WWW::ARDB::Result::ArcEnemy;
2             our $AUTHORITY = 'cpan:GETTY';
3              
4             # ABSTRACT: ARC Enemy result object for WWW::ARDB
5              
6 6     6   168011 use Moo;
  6         26814  
  6         44  
7 6     6   22942 use Types::Standard qw( Str ArrayRef HashRef Maybe );
  6         333007  
  6         72  
8 6     6   13672 use namespace::clean;
  6         20722  
  6         51  
9              
10             our $VERSION = '0.002';
11              
12              
13             has id => (
14             is => 'ro',
15             isa => Str,
16             required => 1,
17             );
18              
19              
20             has name => (
21             is => 'ro',
22             isa => Str,
23             required => 1,
24             );
25              
26              
27             has icon => (
28             is => 'ro',
29             isa => Maybe[Str],
30             default => sub { undef },
31             );
32              
33              
34             has image => (
35             is => 'ro',
36             isa => Maybe[Str],
37             default => sub { undef },
38             );
39              
40              
41             has drop_table => (
42             is => 'ro',
43             isa => ArrayRef,
44             default => sub { [] },
45             );
46              
47              
48             has related_maps => (
49             is => 'ro',
50             isa => ArrayRef,
51             default => sub { [] },
52             );
53              
54              
55             has updated_at => (
56             is => 'ro',
57             isa => Maybe[Str],
58             default => sub { undef },
59             );
60              
61              
62             has _raw => (
63             is => 'ro',
64             isa => HashRef,
65             default => sub { {} },
66             );
67              
68             sub from_hashref {
69 14     14 1 400934 my ($class, $data) = @_;
70              
71             return $class->new(
72             id => $data->{id},
73             name => $data->{name},
74             icon => $data->{icon},
75             image => $data->{image},
76             drop_table => $data->{dropTable} // [],
77             related_maps => $data->{relatedMaps} // [],
78             updated_at => $data->{updatedAt},
79 14   100     330 _raw => $data,
      100        
80             );
81             }
82              
83              
84             sub icon_url {
85 1     1 1 19244 my $self = shift;
86 1 50       8 return unless $self->icon;
87 1 50       14 return 'https://ardb.app' . $self->icon if $self->icon =~ m{^/};
88 0         0 return $self->icon;
89             }
90              
91              
92             sub image_url {
93 1     1 1 4 my $self = shift;
94 1 50       5 return unless $self->image;
95 1 50       12 return 'https://ardb.app' . $self->image if $self->image =~ m{^/};
96 0         0 return $self->image;
97             }
98              
99              
100             sub drops {
101 2     2 1 3287 my $self = shift;
102 2         5 return [ map { $_->{name} } @{$self->drop_table} ];
  5         27  
  2         11  
103             }
104              
105              
106             1;
107              
108             __END__