Class: Notu::MostPlayedTracks
- Inherits:
-
Object
- Object
- Notu::MostPlayedTracks
- Includes:
- Enumerable
- Defined in:
- lib/notu/most_played_tracks.rb
Constant Summary collapse
- PERIODS =
{ 'last_week' => 'week', 'last_month' => '1month', 'last_3_months' => '3month', 'last_6_months' => '6month', 'last_year' => 'year', 'overall' => 'overall', }
Instance Attribute Summary collapse
-
#library ⇒ Object
readonly
Returns the value of attribute library.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(library, options = {}) ⇒ MostPlayedTracks
constructor
A new instance of MostPlayedTracks.
Constructor Details
#initialize(library, options = {}) ⇒ MostPlayedTracks
Returns a new instance of MostPlayedTracks.
18 19 20 21 22 23 |
# File 'lib/notu/most_played_tracks.rb', line 18 def initialize(library, = {}) raise ArgumentError.new("#{self.class}#library must be a library, #{library.inspect} given") unless library.is_a?(Library) @library = library = .stringify_keys.reverse_merge('period' => PERIODS.keys.first) self.period = ['period'] end |
Instance Attribute Details
#library ⇒ Object (readonly)
Returns the value of attribute library.
16 17 18 |
# File 'lib/notu/most_played_tracks.rb', line 16 def library @library end |
#period ⇒ Object
Returns the value of attribute period.
16 17 18 |
# File 'lib/notu/most_played_tracks.rb', line 16 def period @period end |
Instance Method Details
#each(&block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/notu/most_played_tracks.rb', line 25 def each(&block) return unless block_given? document = HtmlDocument.get(library.url(path: 'charts', query: { 'rangetype' => PERIODS[period], 'subtype' => 'tracks' })) (document/'table.chart tbody tr').each do |element| artist = (element/'td.subjectCell a').first.text plays_count = (element/'td.chartbarCell a span').text.strip title = (element/'td.subjectCell a').last.text yield(Track.new(artist: artist, plays_count: plays_count, title: title)) end nil end |