]>
Commit | Line | Data |
---|---|---|
011cd8b5 MG |
1 | package WWW::BackpackTF::Currency; |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
bd910ad7 | 6 | our $VERSION = '0.001'; |
011cd8b5 MG |
7 | |
8 | sub new{ | |
9 | my ($class, $name, $content) = @_; | |
10 | $content->{name} = $name; | |
11 | bless $content, $class | |
12 | } | |
13 | ||
14 | sub name { shift->{name} } | |
15 | sub quality { shift->{quality} } | |
16 | sub priceindex { shift->{priceindex}} | |
17 | sub single { shift->{single} } | |
18 | sub plural { shift->{plural} } | |
19 | sub round { shift->{round} } | |
20 | sub craftable { shift->{craftable} eq 'Craftable' } | |
21 | sub tradable { shift->{tradable} eq 'Tradable' } | |
22 | sub defindex { shift->{defindex} } | |
23 | ||
24 | sub quality_name { WWW::BackpackTF::QUALITIES->[shift->{quality}] } | |
25 | sub 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 | ||
33 | 1; | |
34 | __END__ | |
35 | ||
36 | =encoding utf-8 | |
37 | ||
38 | =head1 NAME | |
39 | ||
40 | WWW::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 | ||
60 | WWW::BackpackTF::Currency is a class representing information about a currency. | |
61 | ||
62 | =head2 METHODS | |
63 | ||
64 | =over | |
65 | ||
66 | =item B<name> | |
67 | ||
68 | The name of the currency. | |
69 | ||
70 | =item B<quality> | |
71 | ||
72 | The quality integer of the currency. Usually 6 (corresponding to the Unique quality). | |
73 | ||
74 | =item B<quality_name> | |
75 | ||
76 | The quality of the currency as a human-readable string. Usually 'Unique'. | |
77 | ||
78 | =item B<priceindex> | |
79 | ||
80 | The priceindex of a currency. Indicates a crate series or unusual effect. Usually 0. | |
81 | ||
82 | =item B<craftable> | |
83 | ||
84 | True if the currency is craftable, false otherwise. Usually true. | |
85 | ||
86 | =item B<tradable> | |
87 | ||
88 | True if the currency is tradable, false otherwise. Usually true. | |
89 | ||
90 | =item B<single> | |
91 | ||
92 | The singular form of the currency. | |
93 | ||
94 | =item B<plural> | |
95 | ||
96 | The plural form of the currency. | |
97 | ||
98 | =item B<round> | |
99 | ||
100 | The number of decimal places this currency should be rounded to. | |
101 | ||
102 | =item B<defindex> | |
103 | ||
104 | The definition index of the currency. | |
105 | ||
106 | =item B<stringify>(I<$count>) | |
107 | ||
108 | Rounds 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 | ||
114 | L<http://backpack.tf/api/currencies> | |
115 | ||
116 | =head1 AUTHOR | |
117 | ||
118 | Marius Gavrilescu, E<lt>marius@ieval.roE<gt> | |
119 | ||
120 | =head1 COPYRIGHT AND LICENSE | |
121 | ||
bd910ad7 | 122 | Copyright (C) 2014, 2015 by Marius Gavrilescu |
011cd8b5 MG |
123 | |
124 | This library is free software; you can redistribute it and/or modify | |
125 | it under the same terms as Perl itself, either Perl version 5.18.2 or, | |
126 | at your option, any later version of Perl 5 you may have available. | |
127 | ||
128 | ||
129 | =cut |