lib/Finance/Robinhood/Equity/Ratings.pm

filter: Statementstmt 46.5% 20 / 43 Branchbran n/a Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 61.1% 11 / 18 Podpod 100% 6 / 6 totaltotal 52.0% 39 / 75 CC 3 SCAR 5.1
CC
3
Cov
47%
_test_instrument
2.9
_test_stringify
2.5
buy
2.0
CRAP 1.7
« lib/Finance/Robinhood/Options/Chain.pm ↑ Summary lib/Finance/Robinhood/Equity/PriceMovement.pm »
1 package Finance::Robinhood::Equity::Ratings;
2  
3 =encoding utf-8
4  
5 =for stopwords watchlist watchlists untradable urls
6  
7 =head1 NAME
8  
9 Finance::Robinhood::Equity::Ratings - Morningstar ratings for equity
10 instruments Watchlist
11  
12 =head1 SYNOPSIS
13  
14 use Finance::Robinhood;
15 my $rh = Finance::Robinhood->new;
16  
17 my $msft = $rh->equity_instrument_by_id('50810c35-d215-4866-9758-0ada4ac79ffa');
18 my $ratings = $msft->ratings;
19  
20 # TODO
21  
22 =cut
23  
24 1 our $VERSION = '0.92_003';
25 1 ▶use Mojo::Base-base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Mojo::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 ▶sub _test__init {
Subroutine _test__init: called CC=1 SCAR=4.1
29 1 my $rh = t::Utility::rh_instance(1);
30 0 my $msft = $rh->equity_instrument_by_id(
31 '50810c35-d215-4866-9758-0ada4ac79ffa'); # MSFT
32 0 my $ratings = $msft->ratings;
33 0 isa_ok($ratings, __PACKAGE__);
34 0 t::Utility::stash('RATINGS', $ratings); # Store it for later
35 }
36 0 ▶use overload '""' => sub ($s, @) { $s->{instrument_id} }, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
37  
38 1 ▶sub _test_stringify {
Subroutine _test_stringify: called CC=2 SCAR=9.2
39 1 ▶ t::Utility::stash('RATINGS') // skip_all();
Condition50%1/2
t::Utility::stash("RATINGS") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("RATINGS") // skip_all()
t::Utility::stash("RATINGS") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("RATINGS")B= skip_all()
ABresult
1X1
011
000
40 0 like(+t::Utility::stash('RATINGS'),
41 qr'^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'i
42 );
43 }
44 #
45 1 has _rh => undef => weak => 1;
46  
47 =head1 METHODS
48  
49 =head2 C<buy( )>
50  
51 Returns a list of buy ratings.
52  
53 =cut
54  
55 0 ▶sub buy ($s) {
Subroutine buy: not called CC=1 SCAR=6.9
Pod documented
56 0 map { $_->{text} } grep { $_->{type} eq 'buy' } @{$s->{ratings}};
57 }
58 1 ▶sub _test_buy { skip_all() }
Subroutine _test_buy: called CC=1 SCAR=0.0
59  
60 =head2 C<sell( )>
61  
62 Returns a list of sell ratings.
63  
64 =cut
65  
66 0 ▶sub sell ($s) {
Subroutine sell: not called CC=1 SCAR=6.9
Pod documented
67 0 map { $_->{text} } grep { $_->{type} eq 'sell' } @{$s->{ratings}};
68 }
69 1 ▶sub _test_sell { skip_all() }
Subroutine _test_sell: called CC=1 SCAR=0.0
70  
71 =head2 C<hold( )>
72  
73 Returns a list of hold ratings.
74  
75 =cut
76  
77 0 ▶sub hold ($s) {
Subroutine hold: not called CC=1 SCAR=6.9
Pod documented
78 0 map { $_->{text} } grep { $_->{type} eq 'hold' } @{$s->{ratings}};
79 }
80 1 ▶sub _test_hold { skip_all() }
Subroutine _test_hold: called CC=1 SCAR=0.0
81  
82 =head2 C<all( )>
83  
84 Returns a hash reference with the following keys: C<buy>, C<sell>, C<hold>. The
85 values are ratings.
86  
87 =cut
88  
89 0 ▶sub all ($s) {
Subroutine all: not called CC=1 SCAR=6.9
Pod documented
90 0 {buy => [$s->buy], hold => [$s->hold], sell => [$s->sell]}
91 }
92  
93 1 ▶sub _test_all {
Subroutine _test_all: called CC=1 SCAR=0.0
94  
95 #t::Utility::stash('RATINGS') //
96 1 skip_all();
97 }
98  
99 =head2 C<totals( )>
100  
101 Returns a hash reference with the following keys: C<buy>, C<sell>, C<hold>. The
102 values are numbers.
103  
104 =cut
105  
106 0 ▶sub totals ($s) {
Subroutine totals: not called CC=1 SCAR=6.9
Pod documented
107 {buy => $s->{summary}{num_buy_ratings},
108 hold => $s->{summary}{num_hold_ratings},
109 sell => $s->{summary}{num_sell_ratings}
110 }
111 0 }
112  
113 1 ▶sub _test_totals {
Subroutine _test_totals: called CC=1 SCAR=0.0
114  
115 #t::Utility::stash('RATINGS') //
116 1 skip_all();
117  
118 #my $instrument = t::Utility::stash('RATINGS')->instrument;
119 #isa_ok( $instrument, 'Finance::Robinhood::Instrument' );
120 }
121  
122 =head2 C<instrument( )>
123  
124 my $instrument = $ratings->instrument;
125  
126 Returns an iterator containing Finance::Robinhood::News elements.
127  
128 =cut
129  
130 0 ▶sub instrument ($s) { $s->_rh->equity_instrument_by_id($s->{instrument_id}) }
Subroutine instrument: not called CC=1 SCAR=6.9
Pod documented
131  
132 1 ▶sub _test_instrument {
Subroutine _test_instrument: called CC=2 SCAR=10.5
133 1 ▶ t::Utility::stash('RATINGS') // skip_all();
Condition50%1/2
t::Utility::stash("RATINGS") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("RATINGS") // skip_all()
t::Utility::stash("RATINGS") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("RATINGS")B= skip_all()
ABresult
1X1
011
000
134 0 my $instrument = t::Utility::stash('RATINGS')->instrument;
135 0 isa_ok($instrument, 'Finance::Robinhood::Equity::Instrument');
136 }
137  
138 =head1 LEGAL
139  
140 This is a simple wrapper around the API used in the official apps. The author
141 provides no investment, legal, or tax advice and is not responsible for any
142 damages incurred while using this software. This software is not affiliated
143 with Robinhood Financial LLC in any way.
144  
145 For Robinhood's terms and disclosures, please see their website at
146 https://robinhood.com/legal/
147  
148 =head1 LICENSE
149  
150 Copyright (C) Sanko Robinson.
151  
152 This library is free software; you can redistribute it and/or modify it under
153 the terms found in the Artistic License 2. Other copyrights, terms, and
154 conditions may apply to data transmitted through this module. Please refer to
155 the L<LEGAL> section.
156  
157 =head1 AUTHOR
158  
159 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
160  
161 =cut
162  
163 1 1;
« lib/Finance/Robinhood/Options/Chain.pm ↑ Summary lib/Finance/Robinhood/Equity/PriceMovement.pm »