Bump version and update Changes
[www-backpacktf.git] / lib / WWW / BackpackTF / Currency.pm
CommitLineData
011cd8b5
MG
1package WWW::BackpackTF::Currency;
2
3use 5.014000;
4use strict;
5use warnings;
0aaa9b98 6our $VERSION = '0.001001';
011cd8b5
MG
7
8sub new{
9 my ($class, $name, $content) = @_;
10 $content->{name} = $name;
11 bless $content, $class
12}
13
14sub name { shift->{name} }
15sub quality { shift->{quality} }
16sub priceindex { shift->{priceindex}}
17sub single { shift->{single} }
18sub plural { shift->{plural} }
19sub round { shift->{round} }
20sub craftable { shift->{craftable} eq 'Craftable' }
21sub tradable { shift->{tradable} eq 'Tradable' }
22sub defindex { shift->{defindex} }
23
24sub quality_name { WWW::BackpackTF::QUALITIES->[shift->{quality}] }
25sub stringify {
26 my ($self, $nr) = @_;
27 my $round = $self->round;
28 $nr = sprintf "%.${round}f", $nr;
29 my $suf = $nr == 1 ? $self->single : $self->plural;
30 "$nr $suf";
31}
32
331;
34__END__
35
36=encoding utf-8
37
38=head1 NAME
39
40WWW::BackpackTF::Currency - Class representing currency information
41
42=head1 SYNOPSIS
43
44 my @currencies = $bp->get_currencies;
45 my $currency = $currencies[0];
46 say 'Name: ', $currency->name;
47 say 'Quality (number): ', $currency->quality;
48 say 'Quality (human-readable): ', $currency->quality_name;
49 say 'Priceindex: ', $currency->priceindex;
50 say 'Craftable: ', ($currency->craftable ? 'YES' : 'NO');
51 say 'Tradable: ', ($currency->tradable ? 'YES' : 'NO');
52 say 'Singular form: ', $currency->single;
53 say 'Plural form: ', $currency->plural;
54 say 'Round to this many decimal places: ', $currency->round;
55 say 'Defindex: ', $currency->defindex;
56 say '3.15271 units of this currency is: ', $currency->stringify(3.15271); # example return values: "3.15 keys", "3.15 ref", "3.15 buds"
57
58=head1 DESCRIPTION
59
60WWW::BackpackTF::Currency is a class representing information about a currency.
61
62=head2 METHODS
63
64=over
65
66=item B<name>
67
68The name of the currency.
69
70=item B<quality>
71
72The quality integer of the currency. Usually 6 (corresponding to the Unique quality).
73
74=item B<quality_name>
75
76The quality of the currency as a human-readable string. Usually 'Unique'.
77
78=item B<priceindex>
79
80The priceindex of a currency. Indicates a crate series or unusual effect. Usually 0.
81
82=item B<craftable>
83
84True if the currency is craftable, false otherwise. Usually true.
85
86=item B<tradable>
87
88True if the currency is tradable, false otherwise. Usually true.
89
90=item B<single>
91
92The singular form of the currency.
93
94=item B<plural>
95
96The plural form of the currency.
97
98=item B<round>
99
100The number of decimal places this currency should be rounded to.
101
102=item B<defindex>
103
104The definition index of the currency.
105
106=item B<stringify>(I<$count>)
107
108Rounds I<$count> to the number of decimal places returned by B<round>, then appends a space and the correct singular/plural form of the currency.
109
110=back
111
112=head1 SEE ALSO
113
114L<http://backpack.tf/api/currencies>
115
116=head1 AUTHOR
117
118Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
119
120=head1 COPYRIGHT AND LICENSE
121
0aaa9b98 122Copyright (C) 2014-2016 by Marius Gavrilescu
011cd8b5
MG
123
124This library is free software; you can redistribute it and/or modify
125it under the same terms as Perl itself, either Perl version 5.18.2 or,
126at your option, any later version of Perl 5 you may have available.
127
128
129=cut
This page took 0.017132 seconds and 4 git commands to generate.